0
0
SQLquery~5 mins

YEAR, MONTH, DAY extraction in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL function YEAR() do?
The YEAR() function extracts the year part from a date or datetime value.
Click to reveal answer
beginner
How do you extract the month from a date in SQL?
Use the MONTH() function to get the month number (1-12) from a date or datetime value.
Click to reveal answer
beginner
What is the purpose of the DAY() function in SQL?
The DAY() function extracts the day of the month (1-31) from a date or datetime value.
Click to reveal answer
intermediate
Write a SQL query to get the year, month, and day from a column named order_date.
SELECT YEAR(order_date) AS year, MONTH(order_date) AS month, DAY(order_date) AS day FROM your_table;
Click to reveal answer
beginner
Why is extracting year, month, and day useful in databases?
It helps to filter, group, or analyze data based on parts of dates, like finding sales in a specific month or year.
Click to reveal answer
Which SQL function extracts the year from a date?
ADAY()
BMONTH()
CDATEPART()
DYEAR()
What does MONTH('2024-06-15') return?
A6
B15
C2024
DNULL
If you want to get the day from a date, which function do you use?
AMONTH()
BDAY()
CYEAR()
DDATE()
Which SQL query correctly extracts year, month, and day from birth_date?
ASELECT YEAR(birth_date), MONTH(birth_date), DAY(birth_date) FROM table;
BSELECT DATE(birth_date) FROM table;
CSELECT EXTRACT(YEAR, birth_date) FROM table;
DSELECT GETDATE(birth_date) FROM table;
What is the output of DAY('2024-06-01')?
A2024
B6
C1
DNULL
Explain how to extract the year, month, and day from a date column in SQL and why it might be useful.
Think about how you can break a date into smaller parts to analyze data.
You got /3 concepts.
    Write a simple SQL query to select the year, month, and day from a column named created_at in a table called users.
    Use the YEAR(), MONTH(), and DAY() functions in the SELECT clause.
    You got /5 concepts.