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 NameType
daydate

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

  • day contains valid date values
  • day values are unique
  • Result can be returned in any order

Visualization

Tap to expand
Convert Date Format Problem OverviewInput Table: Daysday (date)2022-05-082021-08-092020-06-26...TO_CHARFunctionPattern: Day, Month DD, YYYYOutput: Formattedday (formatted string)Sunday, May 08, 2022Monday, August 09, 2021Friday, June 26, 2020...Each date is converted to human-readable format with day name, month name, day and year
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
Asked in
Amazon 15 Microsoft 12 Google 8
22.3K Views
Medium Frequency
~8 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen