Convert Date Format - Problem
You are given a table Days containing dates. Write a SQL solution to convert each date into a formatted string.
Table: Days
| Column Name | Type |
|---|---|
| day | date |
The day column contains unique date values.
Task: Convert each date to the format "day_name, month_name day, year" (e.g., "Friday, January 15, 2021").
Return the result table in any order.
Table Schema
Days
| Column Name | Type | Description |
|---|---|---|
day
PK
|
date | Date value to be formatted |
Primary Key: day
Note: Each row contains a unique date that needs to be converted to a specific string format
Input & Output
Example 1 — Basic Date Formatting
Input Table:
| day |
|---|
| 2022-05-08 |
| 2021-08-09 |
| 2020-06-26 |
Output:
| day |
|---|
| Sunday , May 08, 2022 |
| Monday , August 09, 2021 |
| Friday , June 26, 2020 |
💡 Note:
Each date is converted to the format "day_name, month_name day, year". Note that PostgreSQL's TO_CHAR function pads day and month names with spaces to maintain consistent width.
Example 2 — Different Years and Months
Input Table:
| day |
|---|
| 2019-12-31 |
| 2023-01-01 |
Output:
| day |
|---|
| Tuesday , December 31, 2019 |
| Sunday , January 01, 2023 |
💡 Note:
The formatting works consistently across different years, including year boundaries like New Year's Eve and New Year's Day.
Constraints
-
daycontains valid date values -
dayvalues are unique - Result can be returned in any order
Visualization
Tap to expand
Understanding the Visualization
1
Input
Raw date values from table
2
Format
Apply TO_CHAR formatting
3
Output
Human-readable date strings
Key Takeaway
🎯 Key Insight: Use TO_CHAR with proper format patterns for consistent date string formatting in PostgreSQL
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code