0
0
SQLquery~5 mins

DATE arithmetic (DATEDIFF, DATE_ADD) in SQL - Cheat Sheet & Quick Revision

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

DATEDIFF calculates the number of days between two dates. It tells you how many days separate one date from another.

Click to reveal answer
beginner
How do you add 10 days to a date in SQL?

You use DATE_ADD with an interval of 10 days. For example: DATE_ADD('2024-01-01', INTERVAL 10 DAY) gives you the date 10 days after January 1, 2024.

Click to reveal answer
beginner
What is the difference between DATEDIFF and DATE_ADD?

DATEDIFF finds the number of days between two dates. DATE_ADD changes a date by adding a certain amount of time (days, months, etc.) to it.

Click to reveal answer
intermediate
Write a SQL query to find how many days have passed since '2024-01-01' until today.

SELECT DATEDIFF(CURRENT_DATE, '2024-01-01');

This returns the number of days from January 1, 2024, to today.

Click to reveal answer
beginner
How can you add 3 months to a date using SQL?

Use DATE_ADD with INTERVAL 3 MONTH. Example: DATE_ADD('2024-01-01', INTERVAL 3 MONTH) gives April 1, 2024.

Click to reveal answer
What does DATEDIFF('2024-01-10', '2024-01-01') return?
A1
B9
C11
D10
Which SQL function adds a time interval to a date?
ADATE_ADD
BDATEDIFF
CDATE_SUB
DNOW
How do you subtract 5 days from a date in SQL?
ADATE_ADD(date, INTERVAL 5 DAY)
BDATEDIFF(date, 5)
CDATE_SUB(date, INTERVAL 5 DAY)
DSUBDATE(date, 5)
What will DATE_ADD('2024-02-28', INTERVAL 1 DAY) return?
A'2024-02-29'
B'2024-03-01'
C'2024-02-28'
DError
If you want to find the number of days between two dates, which function do you use?
ADATE_ADD
BNOW
CCURDATE
DDATEDIFF
Explain how to calculate the number of days between two dates in SQL and give an example.
Think about how to find the difference in days between '2024-01-01' and '2024-01-10'.
You got /3 concepts.
    Describe how to add a time interval (like days or months) to a date in SQL and provide a sample query.
    Consider adding 10 days or 3 months to a specific date.
    You got /3 concepts.