Video in progress
What is the difference between `timestamp` and `timestamptz`, and which Java types match them?
timestamp stores a "wall clock" time with no time zone, while timestamptz stores an exact instant (internally in UTC) and displays it according to the session time zone. In Java, LocalDateTime matches the first, and OffsetDateTime or Instant the second.
📖 Answer
The name is misleading: timestamptz does not store the zone. It converts the incoming value to UTC and stores that, and when you read it, it displays the value according to the TimeZone setting.
SET TimeZone = 'Asia/Tashkent';
SELECT '2026-11-03 10:00:00+00'::timestamptz; -- 2026-11-03 15:00:00+05
SELECT '2026-11-03 10:00:00+00'::timestamp; -- 2026-11-03 10:00:00 (the zone was dropped)
When to use which:
- the time of an event (order created, payment went through):
timestamptz. It's the same instant no matter which zone the server is in. - local times like "every day at 09:00", or a birth date:
timestamp/date.
A bug you see a lot on prod: everything is timestamp, the server runs in UTC, the developer's laptop is on Tashkent time. In tests everything is correct, and on prod the times are shifted by 5 hours.
In Hibernate 6, Instant and OffsetDateTime map well to timestamptz. Many projects also set spring.jpa.properties.hibernate.jdbc.time_zone=UTC.
Sign up to mark studied questions and save your progress.