Recall & Review
beginner
What does the MySQL function DATE_ADD() do?DATE_ADD() adds a specified time interval to a date and returns the new date.
Click to reveal answer
beginner
How does DATE_SUB() differ from DATE_ADD()?
DATE_SUB() subtracts a specified time interval from a date, while DATE_ADD() adds it.
Click to reveal answer
beginner
Write a simple example of DATE_ADD() to add 5 days to '2024-06-01'.
SELECT DATE_ADD('2024-06-01', INTERVAL 5 DAY); -- Result: '2024-06-06'
Click to reveal answer
intermediate
What types of intervals can you use with DATE_ADD() and DATE_SUB()?
You can use intervals like DAY, MONTH, YEAR, HOUR, MINUTE, SECOND, and more.
Click to reveal answer
beginner
Why would you use DATE_SUB() in a database query?
To find a date before a given date, such as finding records older than a certain number of days.
Click to reveal answer
What will this query return? SELECT DATE_ADD('2024-06-10', INTERVAL 3 DAY);
✗ Incorrect
Adding 3 days to June 10, 2024 results in June 13, 2024.
Which function subtracts time from a date in MySQL?
✗ Incorrect
DATE_SUB() subtracts a specified interval from a date.
What interval keyword would you use to add 2 months using DATE_ADD()?
✗ Incorrect
MONTH is the correct interval keyword to add months.
If you want to find the date 10 days before today, which query is correct?
✗ Incorrect
DATE_SUB with 10 days subtracts 10 days from today.
Can DATE_ADD() and DATE_SUB() be used with time intervals like HOUR and MINUTE?
✗ Incorrect
Both functions support many interval types including HOUR and MINUTE.
Explain how DATE_ADD() and DATE_SUB() work in MySQL and give an example of each.
Think about adding or subtracting time intervals from a date.
You got /4 concepts.
Describe a real-life situation where you might use DATE_SUB() in a database query.
Consider situations like finding expired items or past events.
You got /3 concepts.