Epoch & Unix Timestamp in PostgreSQL

Get the current epoch timestamp

SELECT extract(epoch FROM now())::bigint;

Convert epoch to date

SELECT to_timestamp(1718200000);

Convert date to epoch

SELECT extract(epoch FROM timestamptz '2026-06-12 00:00:00+00')::bigint;

PostgreSQL notes

to_timestamp returns timestamptz (an absolute instant). extract(epoch FROM …) on a bare timestamp interprets it in the session TimeZone — use timestamptz with an explicit offset to stay unambiguous.

Check any value live with the epoch converter, or read what Unix time actually counts.

Other languages

C · C# · C++ · Dart · Go · Java · JavaScript · Kotlin · MySQL · Perl · PHP · Python · R · Ruby · Rust · Scala · SQLite · Swift · TypeScript