Getting date with timezone offset

前端 未结 3 1042
情深已故
情深已故 2020-12-15 07:02

I am trying to extract the date from a query in postgres. The timestamp is stored as UTC, so if I have 1/1/2014 02:00:00, I want the date in pacific time, to be 12/31/2013,

3条回答
  •  再見小時候
    2020-12-15 07:43

    I figured it out, using the interval, I can subtract the offset and then get the date.

    SELECT '1-1-2014 02:00:00'::timestamp + INTERVAL '1 hour' * extract(timezone_hour FROM '1-1-2014 00:02:00'::timestamp at time zone 'America/Los_Angeles');
    

    Adding the answer here, since I am sure this question might be something others would want to know.

提交回复
热议问题