1

According to the documentation, "for timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the system's TimeZone parameter, and is converted to UTC using the offset for the timezone zone.".

This explanation appears to conflict with the statement regarding the handling of timestamp with time zone. For instance, I set the system's TimeZone to US/Eastern and executed the command select '2025-02-12T6:30:04'::timestamptz. I anticipated the result to be 2025-02-12T11:30:04+00:00, as there is no time zone specified in the input string 2025-02-12T6:30:04. Therefore, it should default to the system's TimeZone parameter, which is US/Eastern, and subsequently convert to UTC using the offset between UTC and US/Eastern.

However, the actual return result was 2025-02-12T06:30:04-05:00, which represents a timestamp in US/Eastern rather than UTC.

Am I misunderstanding the documentation, or is there an error in the documentation itself?

5
  • 1
    Are you sure the problem isn't just the way the result is being displayed? Commented Feb 12 at 23:14
  • 1
    This question is similar to: Ignoring time zones for Postgres timestamps. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Feb 12 at 23:38
  • 2
    1) Did you really SET TimeZone = 'EST'? Not a good idea as that pins to one of two time zones that exist on the east coast. Better to use something like set timezone = 'US/Eastern';. 2) The result is correct, this '2025-02-12T6:30:04' is taken to be at EST and rotated to UTC for storage. On retrieval it is rotated back from UTC to EST. To get what you want: select '2025-02-12T6:30:04'::timestamptz at time zone 'UTC'; 2025-02-12 11:30:04. 4) For the complete why?, see Time Stamps. Commented Feb 12 at 23:53
  • @MarkRansom That's what I am trying to understand. Are both '2025-02-12T11:30:04+00:00' and '2025-02-12T06:30:04-05:00` in UTC but they just display differently? Commented Feb 13 at 3:12
  • Again read this link Time Stamps section it explains what you are seeing. Commented Feb 13 at 17:20

1 Answer 1

2

Both results represent exactly the same timestamptz value, the same point in universal time (Einstein aside). Only the display differs. See what happens when I run this locally, with timezone = Europe/Vienna:

test=> SELECT timestamptz '2025-02-12T11:30:04+00:00' AS t1
test->      , timestamptz '2025-02-12T06:30:04-05:00' AS t2
test->      , timestamptz '2025-02-12T06:30:04-05:00' = timestamptz '2025-02-12T11:30:04+00:00' AS the_same;

           t1           |           t2           | the_same 
------------------------+------------------------+----------
 2025-02-12 12:30:04+01 | 2025-02-12 12:30:04+01 | t

I get a third, equivalent display for the same point in time. Postgres displays timestamptz values according to the timezone setting of the session. If you prefer timestamptz values to be displayed for the UTC timezone, you might tell Postgres that you currently operate in that time zone by setting your session variable: SET timezone = 'UTC';. Of course, Postgres will then assume UTC where no time zone is given explicitly.

Also, time zone abbreviations like 'EST' are a crude tool that only encode a constant time offset. To be smart about daylight saving time (and other political changes across history), use a time zone name, like 'US/Eastern' - like Adrian already suggested in the comments.

See the manual on time zones and:

Don't fall for the idea that the data type timestamp with time zone would somehow carry a time zone. It does not. See:

Sign up to request clarification or add additional context in comments.

4 Comments

Hi thanks for the details! I understand that both '2025-02-12T11:30:04+00:00' and '2025-02-12T06:30:04-05:00` are the same. I was trying to understand what the documentation says 'for timestamp with time zone, the internally stored value is always in UTC'. But if I set the timezone to be 'US/Eastern', the stored value is not in UTC. Or you are saying that both '2025-02-12T11:30:04+00:00' and '2025-02-12T06:30:04-05:00` are in UTC but they just display differently?
@YEL Strictly speaking, the displayed timestamptz literals are not "in UTC". Internally, values are stored in UTC, which is binary identical to timestamp values showing the same clock time. This actually matters. See: dba.stackexchange.com/a/134603/3684
I think I just need to understand what does 'internally' mean ><
Ah I understand it now thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.