Skip to content
Advertisement

Conversion of time zone in snowflake sql

I am doing a conversion of timezone from current_timestamp to ‘US/Eastern’ in snowflake view. I was able to create the view but when I preview the data I am getting Timestamp ‘US/Eastern’ is not recognized error.

I am converting like below:

((CONVERT_TIMEZONE(current_timestamp, 'US/Eastern') - INTERVAL '5 HOUR'))

Advertisement

Answer

Thus looking at TIMEZONE doc‘s LukStorms points, and following the link to the Wikipedia List_of_tz_database_time_zones US/Eastern is the same as America/New_York, thus

((CONVERT_TIMEZONE(current_timestamp, 'America/New_York') - INTERVAL  '5 HOUR'))

But the 2 parameter version is in the form:

CONVERT_TIMEZONE( <target_tz> , <source_timestamp> )

but you are doing ( <source_timestamp>, <target_tz>)

Also the - INTERVAL '5 HOUR' appears the same as “to UTC for the current not in Daylight savings time”, it would seem safer to use the complete version of CONVERT_TIMEZONE to do the to UTC part. it would seem you should use the form from the examples:

-- Convert a "wallclock" time in Warsaw to the matching "wallclock" time in UTC

select convert_timezone('Europe/Warsaw', 'UTC', '2019-01-01 00:00:00'::timestamp_ntz) as conv;

thus use :

convert_timezone('America/New_York', 'UTC', current_timestamp::timestamp_ntz)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement