Skip to main content
0 reactions

timestamp vs timestamptz in PostgreSQL

Featured card for timestamp vs timestamptz in PostgreSQL, comparing timestamptz (a moment in time, stored in UTC, right in every zone) with timestamp (a clock reading, no time zone, drops +05:30).
timestamp vs timestamptz in PostgreSQL.

Both types hold a date and a time. timestamptz, short for timestamp with time zone, stores a moment: PostgreSQL converts it to UTC and shows it in your time zone. timestamp stores only the clock reading, and drops any time zone you give it. Here’s timestamp vs timestamptz in PostgreSQL, side by side in one table.

Every command and output on this page is real, from PostgreSQL 19 on macOS.

Syntax

SyntaxSQL
column_name timestamptz
column_name timestamp
  • timestamptz: a moment in time. It’s PostgreSQL’s short name for timestamp with time zone.
  • timestamp: a date and a clock time with no time zone, the same as timestamp without time zone.
  • Both take 8 bytes.

See Date/Time Types (opens in a new tab) in the PostgreSQL documentation.

The Example

A team calendar stores when a meeting starts, once in each type. Then it looks at the same table from India and from London.

Step 1: Create a Test Database

Connect to your server with psql as the postgres user, as Part 2 of the PostgreSQL Tutorial shows. psql connects you to the postgres database, and its prompt is postgres=#.

Create a database for the example and connect to it:

postgres=#SQL
CREATE DATABASE calendar;
OutputPlain text
CREATE DATABASE
postgres=#Plain text
\c calendar
OutputPlain text
You are now connected to database "calendar" as user "postgres".

Step 2: Create the Table

calendar=#SQL
CREATE TABLE meetings (title text, starts_at timestamptz, starts_local timestamp);
OutputPlain text
CREATE TABLE

Step 3: Save a Meeting in India’s Time Zone

SET TIME ZONE sets the time zone for your session only. Set it to India’s:

calendar=#SQL
SET TIME ZONE 'Asia/Kolkata';
OutputPlain text
SET

Then save a stand-up at 10:00 in both columns, and look at it:

calendar=#SQL
INSERT INTO meetings (title, starts_at, starts_local) VALUES ('Stand-up', '2026-11-27 10:00', '2026-11-27 10:00');
OutputPlain text
INSERT 0 1
calendar=#SQL
SELECT * FROM meetings;
OutputPlain text
  title   |         starts_at         |    starts_local
----------+---------------------------+---------------------
 Stand-up | 2026-11-27 10:00:00+05:30 | 2026-11-27 10:00:00
(1 row)

Both show 10:00. starts_at also shows the offset, +05:30.

Step 4: Look at It from London

calendar=#SQL
SET TIME ZONE 'Europe/London';
OutputPlain text
SET
calendar=#SQL
SELECT * FROM meetings;
OutputPlain text
  title   |       starts_at        |    starts_local
----------+------------------------+---------------------
 Stand-up | 2026-11-27 04:30:00+00 | 2026-11-27 10:00:00
(1 row)

starts_at now shows 04:30 London time, the same moment as 10:00 in India. starts_local still says 10:00, and nothing tells a reader in London that it meant 10:00 in India.

Step 5: Give a Time Zone in the Value

Save a review at 15:00 India time, with the offset written in the value:

calendar=#SQL
INSERT INTO meetings (title, starts_at, starts_local) VALUES ('Review', '2026-11-27 15:00+05:30', '2026-11-27 15:00+05:30');
OutputPlain text
INSERT 0 1
calendar=#SQL
SELECT * FROM meetings;
OutputPlain text
  title   |       starts_at        |    starts_local
----------+------------------------+---------------------
 Stand-up | 2026-11-27 04:30:00+00 | 2026-11-27 10:00:00
 Review   | 2026-11-27 09:30:00+00 | 2026-11-27 15:00:00
(2 rows)

starts_at converted it to London’s 09:30. starts_local threw the +05:30 away and kept 15:00, so nothing tells you it was India’s 15:00.

Which One to Use

  • Use timestamptz for anything that happens at a moment: an order, a sign-up, a log entry. It’s right for everyone, wherever they are.
  • Use timestamp only for a clock time that doesn’t belong to a time zone, and say so in the column name.

Clean Up

To remove the example, connect to another database and drop the test database:

calendar=#Plain text
\c postgres
OutputPlain text
You are now connected to database "postgres" as user "postgres".
postgres=#SQL
DROP DATABASE calendar;
OutputPlain text
DROP DATABASE

Warning: DROP DATABASE deletes the database and everything in it, and it can’t be undone.

Common Mistakes

MistakeWhat happensDo this instead
timestamp for the moment something happenedA time zone in the value is silently dropped, as the review showed.Use timestamptz.
Expecting timestamptz to remember the time zone it was givenIt stores the moment in UTC; the original time zone isn’t kept.If you need the place, store its time zone name in a column of its own.

FAQ

Does SET TIME ZONE change the server?

No, only your session. When you disconnect, the next session starts with the server’s own time zone again.

Does timestamptz take more space?

No. Both types take 8 bytes.

Conclusion

timestamptz stores a moment and shows it correctly in every time zone, as the stand-up showed in India and London. timestamp keeps only the clock reading and drops time zones without a word. For anything that happens, choose timestamptz.

Additional Resources

Postgres, PostgreSQL and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada, and used with their permission.

0 comments