skip to content

timestamptz and time zones

it stores an instant, not a zone. and the hour in march that never happened.

address
everything.types.timestamptz
part
part 6, types and values
chapter
chapter 5 of 11
reading time
8 min

a timestamptz stores an instant, a point on the world's one timeline, as UTC. it doesn't store a time zone. the session's TimeZone setting decides how it's read from text and printed back. a plain timestamp is a wall-clock reading with no zone at all.

AT TIME ZONE converts between the two, and a clock change makes some wall times happen twice and others never.

the picture

you know how "with time zone" sounds like the value carries its zone around? it doesn't. timestamp with time zone stores no zone at all. it stores a moment, and prints it in whatever zone your session says. the type with "without time zone" in its name is the one that's missing something.

think of a photo of the sky at one instant. ask people in four cities what their clock said when it was taken, and you get four answers, all correct. the photo is the timestamptz. the four clocks are four TimeZone settings printing it.

TimeZone =
signup.sql2026-03-29 03:30:00+02
  1. 1SET TimeZone = 'Europe/Paris';
  2. 2SELECT created_at FROM customers WHERE id = 12;

paris had just changed its clocks: at 01:00 UTC the wall clock jumped from 02:00 to 03:00, so half an hour later it says 03:30, and the offset is +02 where it was +01 an hour before.

the signup: one instantthe clock jumps an hour
real output, postgres 18.6 (PGlite 0.5.12) · timestamptz
one signup, one stored value, four sessions. pick a TimeZone: the query and the stored bytes never change, only the printing does. the line is the instant. the dashed cut is where paris's clock jumped from 02:00 to 03:00.

it stores an instant

here's that customer, under two settings. the value doesn't move; the text does:

sqldb=shop
SET TimeZone = 'UTC';
SELECT name, created_at FROM customers WHERE id = 12;
SET TimeZone = 'Asia/Kolkata';
SELECT name, created_at FROM customers WHERE id = 12;
output, from postgres 18.6
#1 · SET
#2 · SELECT 1
nametextcreated_attimestamptz
Ravi Kumar2026-03-29 01:30:00+00
(1 row)
#3 · SET
#4 · SELECT 1
nametextcreated_attimestamptz
Ravi Kumar2026-03-29 07:00:00+05:30
(1 row)

01:30 in UTC, 07:00 in Kolkata, the same 8 bytes on disk. the zone is applied on the way in, when text becomes a timestamptz, and on the way out, when it's printed:

  • in: if the text has an offset or a zone name (+05:30, Europe/Paris), that's used. if not, the session's TimeZone is.
  • out: always the session's TimeZone, with the offset printed after it.

a plain timestamp skips both steps. and it doesn't complain if you hand it an offset; it just drops it:

sqlempty db
SET TimeZone = 'UTC';
SELECT timestamp   '2026-03-29 01:30+05:30' AS plain,
       timestamptz '2026-03-29 01:30+05:30' AS with_tz;
output, from postgres 18.6
#1 · SET
#2 · SELECT 1
plaintimestampwith_tztimestamptz
2026-03-29 01:30:002026-03-28 20:00:00+00
(1 row)

the timestamp kept the wall clock and threw the +05:30 away. the timestamptz used it to find the instant, 20:00 UTC the evening before.

so: timestamptz for things that happened (an order, a login, an event), because what you want later is "when", and you'll want to print it in whichever zone the reader is in. a plain timestamp only for wall-clock times that aren't instants yet: "the shop opens at 09:00, local". a birthday is a date.

AT TIME ZONE, both ways

AT TIME ZONE is the converter, and it goes in both directions depending on what you hand it. that's the classic confusion: the same words, opposite jobs.

convert =
convert.sql
  1. 1SET TimeZone = 'UTC';
  2. 2SELECT timestamptz '2026-03-29 01:30+00' AT TIME ZONE 'Asia/Kolkata' AS result,
  3. 3 pg_typeof(timestamptz '2026-03-29 01:30+00' AT TIME ZONE 'Asia/Kolkata') AS type;
the result for timestamptz AT TIME ZONE
resulttimestamptyperegtype
2026-03-29 07:00:00timestamp without time zone
(1 row)

timestamptz AT TIME ZONE: an instant in, the wall clock in that zone out, as a plain timestamp.

real output, postgres 18.6 (PGlite 0.5.12) · timestamptz
four conversions of 01:30. pick one and watch the result type. AT TIME ZONE on a timestamptz gives the wall clock in that zone; on a timestamp, it reads the wall clock as that zone's and gives the instant. the plain casts use the session's zone, UTC here.
predict the output
sql
SET TimeZone = 'UTC';
SELECT timestamp '2026-03-29 01:30' AT TIME ZONE 'Asia/Kolkata';

a handy reading: instant AT TIME ZONE z asks "what did the clocks in z say?", and wall_clock AT TIME ZONE z asks "when was it, if that was a clock in z?"

the hour that never happened

on 2026-03-29 at 01:00 UTC, paris moved its clocks from 02:00 straight to 03:00. a paris wall time between 02:00 and 03:00 doesn't exist that day. type one in anyway:

typedstoredin_utc
2026-03-29 01:302026-03-29 01:30:00+012026-03-29 00:30:00
2026-03-29 02:002026-03-29 03:00:00+022026-03-29 01:00:00
2026-03-29 02:302026-03-29 03:30:00+022026-03-29 01:30:00
2026-03-29 03:002026-03-29 03:00:00+022026-03-29 01:00:00
2026-03-29 03:302026-03-29 03:30:00+022026-03-29 01:30:00
(5 rows)
real output, postgres 18.6 (PGlite 0.5.12) · timestamptz
paris wall times typed into a timestamptz with TimeZone = Europe/Paris. the two that don't exist aren't rejected: postgres reads them with the offset from before the change (+01), which lands them an hour later, on the same instants as 03:00 and 03:30.

no error, no warning. 02:30 becomes 03:30, and two different inputs now mean the same moment. if you store wall times typed by people, validate them in the zone they meant, or store the instant they meant, not what they typed.

in october it goes the other way. on 2026-10-25 paris sets its clocks back from 03:00 to 02:00, so 02:30 happens twice. postgres picks the second one, after the change, at +01:

sqlempty db
SET TimeZone = 'Europe/Paris';
SELECT timestamptz '2026-10-25 02:30'             AS typed,
       timestamptz '2026-10-25 00:30+00'          AS first_0230,
       timestamptz '2026-10-25 01:30+00'          AS second_0230;
output, from postgres 18.6
#1 · SET
#2 · SELECT 1
typedtimestamptzfirst_0230timestamptzsecond_0230timestamptz
2026-10-25 02:30:00+012026-10-25 02:30:00+022026-10-25 02:30:00+01
(1 row)

the first 02:30 can only be written with its offset (02:30+02), or as UTC.

predict the output
sql
SET TimeZone = 'Europe/Paris';
SELECT timestamptz '2026-03-28 12:00' + interval '1 day',
       timestamptz '2026-03-28 12:00' + interval '24 hours';

the interval's day field and its time field are kept apart for exactly this:

sqlempty db
SET TimeZone = 'Europe/Paris';
SELECT timestamptz '2026-03-28 12:00' + interval '1 day'    AS plus_day,
       timestamptz '2026-03-28 12:00' + interval '24 hours' AS plus_24h;
output, from postgres 18.6
#1 · SET
#2 · SELECT 1
plus_daytimestamptzplus_24htimestamptz
2026-03-29 12:00:00+022026-03-29 13:00:00+02
(1 row)

1 day means "same wall-clock time tomorrow", in the session's zone, so it lands at 12:00 after only 23 real hours. 24 hours means 24 hours, so the clock reads 13:00. both are right, for different questions.

the day depends on where you stand

anything that turns an instant into a calendar day, ::date, date_trunc('day', ...), extract(day ...), does it in the session's zone. the same customers, counted per day, in two places:

sqldb=shop
SET TimeZone = 'UTC';
SELECT count(*) AS signed_up_on_the_29th FROM customers WHERE created_at::date = '2026-03-29';
SET TimeZone = 'America/New_York';
SELECT count(*) AS signed_up_on_the_29th FROM customers WHERE created_at::date = '2026-03-29';
output, from postgres 18.6
#1 · SET
#2 · SELECT 1
signed_up_on_the_29thint8
1
(1 row)
#3 · SET
#4 · SELECT 1
signed_up_on_the_29thint8
0
(1 row)

1 in UTC, 0 in new york, where Ravi signed up on the 28th. that's why an index on created_at::date isn't allowed: its value depends on a setting. (expression indexes shows the error and the fix: name the zone in the expression.) for daily reports, decide whose days they are and say it: (created_at AT TIME ZONE 'Europe/Paris')::date. generate_series has the same issue with daily steps, and a fourth argument for the zone (generate_series).

keylines

  • timestamptz stores an instant, not a zone. TimeZone only changes how it's read and printed.
  • timestamp is a wall clock with no zone, and it silently drops an offset you give it.
  • instant AT TIME ZONE z gives z's wall clock; wall clock AT TIME ZONE z gives the instant.
  • a clock change skips some wall times and repeats others, and postgres doesn't complain.
  • turning an instant into a day needs a zone. say which one.