I have a table with several timestamp columns, basically as follows:
timestamp_utc | timestamp
------------------------------------------------------------
'2020-10-28 08:00:00.000' | '2020-10-28 04:00:00.000'
I know that the first column is in UTC time, while the second is in NY time. I was wondering how I can add the respective timezone. So the result I would like to have it is something like:
timestamp_utc | timestamp
------------------------------------------------------------
'2020-10-28 08:00:00.000Z' | '2020-10-28 04:00:00.000-04'
I have tried doing things like:
>>> select timestamp_utc AT TIME ZONE 'UTC' from table;
'2020-10-28 04:00:00.000-04' /* wrong */
>>> select timestamp AT TIME ZONE 'EST' from table;
'2020-10-28 05:00:00.000-04' /* wrong, it should be 04:00:00 */
So finally tried this for the NY part:
>>> select timestamp_est AT TIME ZONE 'America/New_York' from table;
'2020-10-28 04:00:00.000-04'
So I think when I add the timezone with the location, it works. However, when I try to do with true timezones it is converting the time in addition to adding the timezone?
timestamp_utcandtimestamp(FYI, I would rename that or did you withtimestamp_est)? What is the settingTimeZonefor the server?TimeZoneis not set toEST. SecondESTis really just an offset not a full time zone, hence the error in your conversion. Lastly, what data type you are storing your values as, timestamp vs timestamptz is important. I usedateutilin Python all the the time, but it still depends on the underlying behavior in the database.