Use TO_CHAR, DATE_TRUNC, and format specifiers to display Redshift dates and timestamps in any layout.
Call TO_CHAR(date_or_timestamp, 'format_pattern')
. The first argument is a DATE, TIMESTAMP, or TIMESTAMPTZ column or expression; the second is a text literal containing PostgreSQL-style format specifiers.
Use YYYY
(4-digit year), MM
(2-digit month), DD
, HH24
, MI
, SS
, and text like "-"
or ":"
to build custom strings. Example: 'YYYY-MM-DD'
creates ISO dates; 'Dy, Mon DD'
shows abbreviated names.
Use DATE_TRUNC('part', timestamp)
. Valid parts include year
, quarter
, month
, week
, day
, hour
, and minute
. The function returns a TIMESTAMP set to the lower precision.
Store dates as native DATE
or TIMESTAMP
columns. Format only when selecting data for reports, exporting, or interfacing with APIs.
Wrap the date column with TO_CHAR
: TO_CHAR(o.order_date, 'YYYY-MM-DD')
. Combine with other columns to build a ready-to-load CSV.
Call TO_DATE(text_value, 'format_pattern')
. Example: TO_DATE('31/12/2024','DD/MM/YYYY')
parses European style dates into a proper DATE.
Redshift stores TIMESTAMP
as UTC. Use CONVERT_TIMEZONE('UTC','America/Los_Angeles', ts)
before formatting to display local time, or add TIMESTAMPTZ
in TO_CHAR patterns.
Example: TO_CHAR(o.order_date, 'Dy') AS weekday, TO_CHAR(o.order_date, 'HH24') AS hour
quickly yields categorical fields for funnel or cohort charts.
1) Keep data typed, format only on SELECT. 2) Always quote the pattern string. 3) Use ISO YYYY-MM-DD
for interchange. 4) Test edge cases (leap days, DST shifts).
Redshift defaults to the database locale. Use SET lc_time = 'en_US'
(session-scope) to switch language before calling TO_CHAR
.
DATE_TRUNC always outputs TIMESTAMP. Cast to DATE if needed: DATE_TRUNC('month', order_date)::date
.