0
0
SQLquery~5 mins

DATE_FORMAT and EXTRACT in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL function DATE_FORMAT do?

DATE_FORMAT formats a date or datetime value into a string based on a specified pattern. It helps you display dates in a readable or custom way.

Click to reveal answer
beginner
What is the purpose of the SQL function EXTRACT?

EXTRACT pulls out a specific part (like year, month, day) from a date or time value. It returns that part as a number.

Click to reveal answer
beginner
Write a simple example of DATE_FORMAT to show a date as 'Day-Month-Year'.

Example: DATE_FORMAT('2024-06-15', '%d-%m-%Y') returns '15-06-2024'.

Click to reveal answer
beginner
How do you extract the month from a date using EXTRACT?

Use EXTRACT(MONTH FROM date_column). It returns the month number (1 to 12).

Click to reveal answer
intermediate
What is the difference between DATE_FORMAT and EXTRACT?

DATE_FORMAT converts a date to a formatted string. EXTRACT gets a numeric part from a date (like year or day).

Click to reveal answer
Which SQL function would you use to get the year from a date?
AFORMAT_DATE(date, 'year')
BDATE_FORMAT(date, '%Y-%m-%d')
CGETYEAR(date)
DEXTRACT(YEAR FROM date)
What does DATE_FORMAT('2024-06-15', '%d/%m/%Y') return?
A'15/06/2024'
B'2024/06/15'
C'06/15/2024'
D'15-06-2024'
Which part can EXTRACT NOT get from a date?
AMONTH
BWEEKDAY_NAME
CHOUR
DYEAR
If you want to display a date as 'June 15, 2024', which function helps best?
AEXTRACT
BNOW()
CDATE_FORMAT
DDATEDIFF
What type of value does EXTRACT return?
ANumber
BDate
CString
DBoolean
Explain how to use DATE_FORMAT to change the display of a date.
Think about turning a date into a string with a pattern.
You got /3 concepts.
    Describe how EXTRACT helps when working with dates in SQL.
    Focus on getting specific parts from a date.
    You got /3 concepts.