Problem
Table: Days
|
|
Write a solution to convert each date in Days
into a string formatted as "day_name, month_name day, year"
.
Return the result table in any order.
The result format is in the following example.
Examples
Example 1:
|
|
Solution
Method 1 – Date Formatting in SQL and Pandas
Intuition
We need to convert a date to a string in the format “day_name, month_name day, year”. SQL and Pandas both provide date formatting functions to achieve this.
Approach
- Use SQL date formatting functions to extract the day name, month name, day, and year from the date.
- Concatenate these parts into the required format.
- In Pandas, use the
dt.strftime
method to format the date column.
Code
|
|
|
|
|
|
Complexity
- ⏰ Time complexity:
O(n)
, where n is the number of rows in the Days table. - 🧺 Space complexity:
O(n)
, for storing the result set.