-
Notifications
You must be signed in to change notification settings - Fork 43
/
convert-date-format.sql
55 lines (43 loc) · 1.08 KB
/
convert-date-format.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Description
https://leetcode.com/problems/convert-date-format/
SQL Schema
Table: Days
+-------------+------+
| Column Name | Type |
+-------------+------+
| day | date |
+-------------+------+
day is the primary key for this table.
Write an SQL query 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 query result format is in the following example:
Days table:
+------------+
| day |
+------------+
| 2022-04-12 |
| 2021-08-09 |
| 2020-06-26 |
+------------+
Result table:
+-------------------------+
| day |
+-------------------------+
| Tuesday, April 12, 2022 |
| Monday, August 9, 2021 |
| Friday, June 26, 2020 |
+-------------------------+
Please note that the output is case-sensitive.
*/
# V0
SELECT DATE_FORMAT(day, "%W, %M %e, %Y") AS day
FROM Days;
# V1
# https://goodtecher.com/leetcode-1853-convert-date-format/
SELECT DATE_FORMAT(`day`,'%W, %M %e, %Y') as day FROM Days
# V2
# Time: O(n)
# Space: O(n)
SELECT DATE_FORMAT(day, "%W, %M %e, %Y") AS day
FROM Days;