Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Converting local time to UTC in snowflake

I have sample data as follows:

ship_id | origin_zone |  dt_local
 1234   | Asia/Taipei| 2022-03-31 00:00:00.000

The goal is to convert dt_local into UTC. Here is my sql for that;

select 
   origin_zone,
   dt_local,
   convert_timezone('UTC', origin_zone, dt_local) as utc_time
   
from table;

Plz see screenshot for the output. It seems it is just adding offset of 8 hours to this time, which doesn’t sound true. Because Taipei is 8 hrs ahead of UTC. So I am expecting it to subtract 8 hr from dt_local column.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It seems to me since I am running this query on west coast (America/Los Angeles time, which is 8 hrs behind UTC) its just adding 8 to dt_local time column .

Can I please get some help on how to get the correct UTC time for this column? Help is appreciated.
enter image description here

>Solution :

You have the source and target timezones reversed. It should be:

select 
   origin_zone,
   dt_local,
   convert_timezone(origin_zone, 'UTC', dt_local) as utc_time
   
from table;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading