SQL TO_CHAR

The reverse direction from TO_DATE/TO_TIMESTAMP — formats a date or timestamp INTO a text string, for human-readable display.

What & Why

TO_CHAR(date_or_timestamp, format) converts a date value into formatted text, using the same kind of format-pattern syntax as TO_DATE/TO_TIMESTAMP, just working in the opposite direction. This is the tool for turning a raw 2024-06-28 into something like "June 28, 2024" for a report.

See How It Works

BUSINESS QUESTION

Growth wants signup months formatted for a readable report label.

idcreated_atcountrychannelplanactivated_atchurned_at
1012024-01-15 09:10:00+00USorganicpro2024-01-16 14:25:00+00NULL
1022024-02-10 11:05:00+00CApaidfreeNULL2024-03-20 10:00:00+00
1032024-03-12 16:35:00+00GBreferralpro2024-03-13 08:15:00+00NULL
1042024-04-01 13:20:00+00USorganicfree2024-04-03 12:00:00+00NULL
EXAMPLE QUERY
SELECT
  id AS user_id,
  TO_CHAR(created_at, 'YYYY-MM') AS signup_month_label
FROM growth.users
ORDER BY user_id;
RESULT — exact output from the displayed Queryflo rows
user_idsignup_month_label
1012024-01
1022024-02
1032024-03
1042024-04

TO_CHAR creates one YYYY-MM label for each user signup.

Now You Try

Practice this concept

Growth wants signup months formatted for a readable report label.

Available schema
growth

Prefix tables with growth.table_name.

user_idsignup_month_label
growth.users
ColumnType
idinteger
created_attimestamp with time zone
countrytext
channeltext
plantext
activated_attimestamp with time zone
churned_attimestamp with time zone
legacy_user_codetext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario