0
0
MySQLquery~5 mins

EXTRACT and YEAR/MONTH/DAY in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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'?
AYEAR(birth_date)
BGETYEAR(birth_date)
CEXTRACT(YEAR FROM birth_date)
DDATEPART(YEAR, birth_date)
What will EXTRACT(MONTH FROM '2024-06-15') return?
A6
BNULL
C2024
D15
Which part does EXTRACT(DAY FROM '2023-12-01') return?
A1
B12
C2023
DNULL
Is EXTRACT valid for extracting hour from a DATETIME value?
AOnly for DATE type
BYes
CNo
DOnly for TIMESTAMP type
What does EXTRACT(YEAR FROM NULL) return?
A0
BCurrent year
CError
DNULL
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.