Recall & Review
beginner
What does the EXTRACT function do in MySQL?
The EXTRACT function retrieves a specific part (like year, month, or day) from a date or datetime value.
Click to reveal answer
beginner
How do you extract the year from a date column named 'order_date'?
Use
EXTRACT(YEAR FROM order_date) to get the year part from the date.Click to reveal answer
beginner
Which keyword would you use with EXTRACT to get the month from a date?
Use the keyword
MONTH with EXTRACT, like EXTRACT(MONTH FROM date_column).Click to reveal answer
beginner
Write a query to get the day part from a datetime column named 'created_at'.
SELECT EXTRACT(DAY FROM created_at) AS day_part FROM your_table;
Click to reveal answer
beginner
Can EXTRACT be used on both DATE and DATETIME types?
Yes, EXTRACT works on both DATE and DATETIME types to get parts like year, month, day, hour, minute, and second.
Click to reveal answer
Which of the following extracts the year from a date column 'birth_date'?
✗ Incorrect
EXTRACT(YEAR FROM birth_date) is the standard SQL syntax to extract the year part.
What will EXTRACT(MONTH FROM '2024-06-15') return?
✗ Incorrect
It returns 6 because the month part of the date is June (6).
Which part does EXTRACT(DAY FROM '2023-12-01') return?
✗ Incorrect
It returns 1 because the day part of the date is the 1st.
Is EXTRACT valid for extracting hour from a DATETIME value?
✗ Incorrect
EXTRACT can extract hour, minute, second from DATETIME values.
What does EXTRACT(YEAR FROM NULL) return?
✗ Incorrect
EXTRACT returns NULL when the input date is NULL.
Explain how to use the EXTRACT function to get the year, month, and day from a date in MySQL.
Think about the format EXTRACT(part FROM date).
You got /5 concepts.
Describe the difference between extracting parts from DATE and DATETIME types using EXTRACT.
Consider what extra parts DATETIME has compared to DATE.
You got /4 concepts.