Home > Back-end >  Unexpected result from Redshift TIMEZONE function (convert timestamp column from UTC to another time
Unexpected result from Redshift TIMEZONE function (convert timestamp column from UTC to another time

Time:11-16

Based on my understanding of the documentation, I am expecting the TIMEZONE function to convert any timestamp from UTC (by default) to 'timezone'.

I know for a fact that the timestamp columns of the server I'm pulling data from are set to UTC. Therefore, if I convert the timestamp column to EST, I should see a five hour difference between UTC and EST (according to worldtimebuddy).

However, when I run the following query

select
    time_column
    , timezone('est', time_column) as to_est
from
    my_table
order by
    time_column desc
limit 1

I get

sent_at to_est
2022-11-15 17:50:26.280 2022-11-15 22:50:26.280

If I'm interpreting this correctly, the result is telling me that UTC is five hours behind EST, when really, UTC is five hours ahead of EST (right?).

In other words, I was expecting

sent_at to_est
2022-11-15 17:50:26.280 2022-11-15 12:50:26.280

Why am I seeing a -5 hour difference from UTC to EST instead of 5?

CodePudding user response:

instead of timezone use

convert_timezone('EST', time_column) 

That is the way redshift shows in the manual

the syntax is

 CONVERT_TIMEZONE ( ['source_timezone',] 'target_timezone', 'timestamp')

but the source time zone is by default UTC, so you don't need to add it to your code

  • Related