timezonesnowflake-cloud-data-platform

Converting a column containing UTC values to EST values in Snowflake


I am trying to convert a column that contains UTC values to EST values.

LOAD_DATE_UTC
2022-03-23 20:59:51.000

Expected output:

LOAD_DATE_UTC LOAD_DATE_EST
2022-03-23 20:59:51.000 2022-03-23 16:59:51.000

Approach tried:

SELECT LOAD_DATE_UTC, 
CAST(LOAD_DATE_UTC AS TIMESTAMP_LTZ(9)) AS LOAD_DATE_EST
FROM TABLE_A

The above approach seem to be returning the same value as is. Please advise how I can convert the column to EST values which is set as Local Time Zone at Snowflake configuration level


Solution

  • I believe the idea is to convert to EST (target)- So following approach will suit: CONVERT_TIMEZONE( <source_tz> , <target_tz> , <source_timestamp_ntz> )

    SELECT LOAD_DATE_UTC, 
    CONVERT_TIMEZONE(LOAD_DATE_UTC,'America/New_York',LOAD_DATE_UTC::timestamp_ntz)
    FROM TABLE_A
    

    https://docs.snowflake.com/en/sql-reference/functions/convert_timezone.html#examples