0
0
SQLquery~10 mins

DATE_FORMAT and EXTRACT in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to format the date as 'Year-Month-Day'.

SQL
SELECT DATE_FORMAT(order_date, '[1]') AS formatted_date FROM orders;
Drag options to blanks, or click blank then click option'
A'%Y-%m-%d'
B'%d/%m/%Y'
C'%m-%d-%Y'
D'%H:%i:%s'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong order of year, month, and day.
Using slashes instead of dashes.
Using time format codes instead of date.
2fill in blank
medium

Complete the code to extract the month from the date.

SQL
SELECT EXTRACT([1] FROM order_date) AS order_month FROM orders;
Drag options to blanks, or click blank then click option'
AHOUR
BDAY
CYEAR
DMONTH
Attempts:
3 left
💡 Hint
Common Mistakes
Using DAY instead of MONTH.
Using YEAR when month is needed.
Using HOUR which is for time, not date.
3fill in blank
hard

Fix the error in the code to extract the year from the date.

SQL
SELECT EXTRACT(YEAR [1] order_date) AS order_year FROM orders;
Drag options to blanks, or click blank then click option'
AIN
BBY
CFROM
DON
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the FROM keyword.
Using BY, IN, or ON instead of FROM.
4fill in blank
hard

Fill both blanks to format the date as 'Month/Day/Year' and extract the day.

SQL
SELECT DATE_FORMAT(order_date, '[1]') AS formatted_date, EXTRACT([2] FROM order_date) AS day_part FROM orders;
Drag options to blanks, or click blank then click option'
A'%m/%d/%Y'
B'%Y-%m-%d'
CDAY
DMONTH
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date format codes.
Extracting MONTH instead of DAY.
5fill in blank
hard

Fill all three blanks to format the date as 'Year.Month.Day', extract the year, and extract the month.

SQL
SELECT DATE_FORMAT(order_date, '[1]') AS formatted_date, EXTRACT([2] FROM order_date) AS year_part, EXTRACT([3] FROM order_date) AS month_part FROM orders;
Drag options to blanks, or click blank then click option'
A'%d-%m-%Y'
BYEAR
CMONTH
D'%Y.%m.%d'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date format string.
Mixing up YEAR and MONTH in EXTRACT.