to_char()

A function for formatting dates, timestamps and numeric types

to_char() is a system function for outputting dates, timestamps and numeric values in a specified format.

to_char() was added in PostgreSQL 7.0.

Usage

to_char ( timestamp, text ) → text to_char ( timestamp with time zone, text ) → text
to_char ( interval, text ) → text
to_char ( numeric_type, text ) → text

to_char() converts the provided value into the specified template format; see the PostgreSQL documentation section Template Patterns for Date/Time Formatting for details.

Change history

Work-in-progress

Examples

Basic example for formatting a timestamp using to_char():

postgres=# SELECT to_char(now(), 'YYYY-MM-DD HH24:MI');
     to_char      
------------------
 2021-08-01 10:02
(1 row)

Categories

Date and time, String manipulation

See also

to_timestamp(), to_date(), to_number()