TIMESTAMP and TIMESTAMPTZ store a date and time pair in UTC.
Variants
TIMESTAMP has two variants:
-
TIMESTAMPpresents allTIMESTAMPvalues in UTC. -
TIMESTAMPTZconvertsTIMESTAMPvalues from UTC to the client’s session time zone (unless another time zone is specified for the value). However, it is conceptually important to note thatTIMESTAMPTZdoes not store any time zone data.
The default session time zone is UTC, which means that by default
TIMESTAMPTZ values display in UTC.TIMESTAMPTZ uses the client’s session , while the other simply does not. This behavior extends to functions like now() and extract() on TIMESTAMPTZ values.
A time zone offset of
+00:00 is displayed for all and TIMESTAMP values, but is not stored in the database.TIMESTAMPTZ into a TIMESTAMP at a specified timezone, or to convert a TIMESTAMP into a TIMESTAMPTZ at a specified timezone.
Explore the differences of TIMESTAMP and TIMESTAMPTZ in the following video:
CREATE TABLE timestamps (a INT PRIMARY KEY, b TIMESTAMPTZ);
Create a table with a TIMESTAMP-typed column, with precision
TIMESTAMP can be changed to TIMESTAMPTZ, and TIMESTAMPTZ can be changed to TIMESTAMP:
b column, which is of type TIMESTAMPTZ(5), cannot be changed to a precision level below 5:
Convert a TIMESTAMP to seconds since epoch
Convert a TIMESTAMP to milliseconds since epoch
Convert a TIMESTAMP to microseconds since epoch
Convert an INT (seconds since epoch) to timestamp
Convert a STRING (seconds since epoch) to timestamp
Convert an INT (milliseconds since epoch) to timestamp
Note that TIMESTAMP epoch' is the equivalent of 0::timestamp.

