简体   繁体   中英

Convert timestamp from string to EST time in Synapse

I am new to Synapse Data Warehouse.

Currently, I have a timestamp column named last_update_utc as string data type and it is UTC time. I need to add a new column last_update_est with timestamp as datetime2 data type convert from last_update_utc column - The conversion also needs to account for DST. You can check the sample output below:

id | last_update_utc (string)     | last_update_est (datetime2)
1  | 2020-02-28T17:26:47.483698Z  | 2020-02-28T12:26:47.483698Z
2  | 2021-09-03T22:59:19.093Z     | 2021-09-03T18:59:19.093Z

The first row, It is 5 hours of difference without DST and it is 4 hours of difference with DST. The table name is hub.test and initially, there are id and last_update_utc columns.

Is there a simple function or method to achieve the above task in Synapse DW?

Thanks

Convert string to datetime2 and apply AT TIME ZONE to convert UTC to the required time zone.

SELECT CONVERT(DATETIME2, '2021-09-03T22:59:19.093Z') AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time'as last_update_est

在此处输入图像描述

Refer to this document to learn more on AT TIME ZONE implementation.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM