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.
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.
>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;