Skip to content

to_epoch()

Convert a timestamptz to a Unix epoch time

Since 1.16.0

Given a timestamptz, return the number of seconds since January 1, 1970 (the Unix epoch).

Convert a date to a Unix epoch time:

SELECT to_epoch('2021-01-01 00:00:00+03'::timestamptz);

The output looks like this:

to_epoch
------------
1609448400

The syntax is:

SELECT to_epoch('<date>');
NameTypeDefaultRequiredDescription
dateTIMESTAMPTZ-Timestamp to use to calculate epoch
ColumnTypeDescription
to_epochDOUBLE PRECISIONThe number of seconds since January 1, 1970 (Unix epoch)