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.
| id | created_at | country | channel | plan | activated_at | churned_at |
|---|---|---|---|---|---|---|
| 101 | 2024-01-15 09:10:00+00 | US | organic | pro | 2024-01-16 14:25:00+00 | NULL |
| 102 | 2024-02-10 11:05:00+00 | CA | paid | free | NULL | 2024-03-20 10:00:00+00 |
| 103 | 2024-03-12 16:35:00+00 | GB | referral | pro | 2024-03-13 08:15:00+00 | NULL |
| 104 | 2024-04-01 13:20:00+00 | US | organic | free | 2024-04-03 12:00:00+00 | NULL |
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_id | signup_month_label |
|---|---|
| 101 | 2024-01 |
| 102 | 2024-02 |
| 103 | 2024-03 |
| 104 | 2024-04 |
TO_CHAR creates one YYYY-MM label for each user signup.
Sign up free to try it on a real business scenario