Forum Discussion
SQL Date Formatting
Hi all,
I have a requirement to do an OpenQuery to an Oracle database and the accepted time format in Oracle is "2022-05-01T06:00:00Z". I am wondering how do we convert a normal datetime in SQL server to this format .?
select CONVERT(varchar,GETDATE(),127) this gives - >2022-05-10T06:26:21.740 but not in the above format. Can someone help me to convert this .?
Aju
2 Replies
- olafhelperBronze Contributor
ajupulickal wrote:Oracle database and the accepted time format in Oracle is "2022-05-01T06:00:00Z"
ajupulickal , no it isn't, with the to_date function you can pass any date format to Oracle.
See
- LainRobertsonSilver Contributor
Hey, Aju.
As you've already noted, there's no pre-canned identifier that will produce that exact format. Rather, you have to do it yourself using FORMAT.
Here's an example - noting that you should probably also give preference to using GETUTCDATE() over GETDATE():
SELECT FORMAT(GETUTCDATE(), 'yyyy-MM-ddTHH:mm:ssZ')Cheers,
Lain