PostgreSQL Timestamp Converter

Current Unix Time
Advertisement

PostgreSQL Timestamp Converter

PostgreSQL has excellent built-in support for timestamps and timezones. The two primary functions for Unix timestamp conversion in PostgreSQL are TO_TIMESTAMP(), which converts a Unix integer to a timestamptz (timestamp with timezone) value, and EXTRACT(EPOCH FROM ...), which extracts the Unix timestamp from any datetime expression.

PostgreSQL's timestamptz type stores timestamps in UTC internally and automatically converts to the session timezone for display. This is different from timestamp without time zone (timestamp), which stores the literal datetime string without any timezone information. For most applications, timestamptz is the correct choice for timestamp columns.

PostgreSQL Unix timestamp functions

Unix integer to timestamptz:
SELECT TO_TIMESTAMP(1700000000);
2023-11-14 22:13:20+00

timestamptz to Unix integer:
SELECT EXTRACT(EPOCH FROM NOW())::INT;

Specific datetime to Unix:
SELECT EXTRACT(EPOCH FROM TIMESTAMPTZ '2026-04-17 10:35:00 UTC')::INT;

Display in a specific timezone:
SELECT TO_TIMESTAMP(1700000000) AT TIME ZONE 'Europe/Oslo';

Records from the last 7 days:
SELECT * FROM events WHERE ts > EXTRACT(EPOCH FROM NOW() - INTERVAL '7 days')::INT;

Millisecond precision:
SELECT (EXTRACT(EPOCH FROM NOW()) * 1000)::BIGINT;

Advertisement
// Epoch → Human-readable date

Auto-detects seconds (10 digits), milliseconds (13), microseconds (16), nanoseconds (19)

Invalid timestamp. Please enter a numeric Unix timestamp.
// Date → Epoch timestamp
Please check the values — year (1970–9999), month (1–12), day (1–31), hour (0–23), min/sec (0–59).

Or paste a date string:

Could not parse that date string.
Advertisement

← Back to all tools

Copied!