PostgreSQL 18 reference · Date and Time Functions
PostgreSQL TO_TIMESTAMP() Function
Convert Unix epoch seconds to a timestamp with time zone, or parse text into one with a format pattern.
PostgreSQL 18
Syntax
to_timestamp(seconds) | to_timestamp(text, format)
Parameters
| Parameter | Description |
|---|---|
seconds |
Unix time. |
text, format |
Text and its pattern. |
Return value
timestamp with time zone.
Examples
SELECT to_timestamp(1767225600) AS from_unix;
Output
from_unix ------------------------ 2026-01-01 00:00:00+00 (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT to_timestamp('2026-03-09 7:45 PM', 'YYYY-MM-DD HH12:MI AM') AS parsed;
Output
parsed ------------------------ 2026-03-09 19:45:00+00 (1 row)
Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PostgreSQL 17 | The TZ and OF patterns accept time zone abbreviations and offsets. |
In other languages
DATETIME()· SQLiteUNIXEPOCH()· SQLite
Related
TO_DATE()· Parse text into a date using a format pattern, such as to_date('09/03/2026', 'DD/MM/YYYY').EXTRACT()· Get one field from a date, time or interval, such as the year, month, day of week or epoch seconds.- SQL Date Functions · tutorial