PostgreSQL 18 reference · Date and Time Functions
PostgreSQL TO_CHAR() Function
Format a date, timestamp or number as text with a pattern such as 'DD Mon YYYY' or 'FM999,990.00'.
PostgreSQL 18
Syntax
to_char(value, format)
Parameters
| Parameter | Description |
|---|---|
value |
A timestamp, date, interval or number. |
format |
Date codes: YYYY MM DD Mon Day HH24 MI SS; number codes: 9 digit, 0 forced digit, . , FM (no padding). |
Return value
Text.
Examples
SELECT to_char(DATE '2026-03-09', 'DD Mon YYYY') AS uk,
to_char(TIMESTAMP '2026-03-09 07:45', 'FMDay, HH24:MI') AS weekday_time;
Output
uk | weekday_time -------------+--------------- 09 Mar 2026 | Monday, 07:45 (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT to_char(1234567.891, 'FM9,999,999.00') AS money,
to_char(7, 'FM000') AS padded;
Output
money | padded --------------+-------- 1,234,567.89 | 007 (1 row)
Run this on your computer — see “Get Started” for setup.
In other languages
STRFTIME()· SQLiteFORMAT()· SQLite
Related
TO_DATE()· Parse text into a date using a format pattern, such as to_date('09/03/2026', 'DD/MM/YYYY').TO_TIMESTAMP()· Convert Unix epoch seconds to a timestamp with time zone, or parse text into one with a format pattern.FORMAT()· Build a string from a template: %s inserts text, %I a quoted identifier and %L a quoted literal, for safe dynamic SQL.- SQL Date Functions · tutorial