I want to convert my IST datetime to EST datetime. I tried a few ways but am unable to do it.
SELECT (CAST('2022-07-25 03:06' AS DateTime)) at time zone 'US Eastern Standard Time' AS DATETIME
Output:
2022-07-25 03:06:00.000 -04:00 output is same
Required output in EST timezone
Thanks in advance
For offsets between time zones to work correctly you need to start with time zone-aware data types, such as datetimeoffset
.
For example the following parses a time, including time zone offset, into a datetimeoffset
value:
select cast('2022-07-25 03:06:00.000 +5:30' as datetimeoffset) as IST
Which outputs:
IST |
---|
2022-07-25 03:06:00.0000000 +05:30 |
And to convert that to a time in the US EST time zone:
select cast('2022-07-25 03:06 +05:30' AS datetimeoffset) at time zone 'US Eastern Standard Time' as EST
Which outputs:
EST |
---|
2022-07-24 17:36:00.0000000 -04:00 |
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.