to_char()
Converts time stamp to string according to the given format.
Signature
to_char ( timestamp, text ) → text
to_char ( timestamp with time zone, text ) → text
to_char ( interval, text ) → text
to_char ( numeric_type, text ) → textExamples
SELECT to_char(timestamp '2002-04-20 17:31:12.66', 'HH12:MI:SS');05:31:12SELECT to_char(interval '15h 2m 12s', 'HH24:MI:SS');15:02:12SELECT to_char(125, '999'); 125SELECT to_char(125.8::real, '999D9'); 125.8SELECT to_char(-125.8, '999D99S');125.80-Run against PostgreSQL 18.6 on 2026-09-13. This is the output we got, not the documentation’s.
In other engines
| PostgreSQL | to_char |
|---|---|
| MySQL | DATE_FORMAT(x, '%Y-%m-%d') |
| SQL Server | FORMAT(x, 'yyyy-MM-dd') or CONVERT with a style number |
| Oracle | TO_CHAR(x, 'YYYY-MM-DD') |
| SQLite | strftime('%Y-%m-%d', x) |
Oracle and PostgreSQL share the format-string vocabulary; MySQL and SQLite use strftime-style percent codes; SQL Server uses .NET format strings in FORMAT. Four dialects for one idea.
Want to run this against your own PostgreSQL server from an iPhone, iPad or Mac? These are ours — every connection goes straight from the device to your database, with no account and no server of ours in between.
Signature and description adapted from the PostgreSQL manual, used under the PostgreSQL License. PostgreSQL is a registered trademark of the PostgreSQL Community Association of Canada. This page is not affiliated with the PostgreSQL Global Development Group.