Challenge - 5 Problems
Date Arithmetic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Calculate days difference between two dates
Given the table Events with a column
event_date, what is the output of this query?SELECT DATEDIFF('2024-06-15', '2024-06-10') AS days_diff;SQL
SELECT DATEDIFF('2024-06-15', '2024-06-10') AS days_diff;
Attempts:
2 left
💡 Hint
DATEDIFF returns the number of days between the first date and the second date.
✗ Incorrect
DATEDIFF('2024-06-15', '2024-06-10') calculates how many days from June 10 to June 15, which is 5 days.
❓ query_result
intermediate1:30remaining
Add days to a date using DATE_ADD
What is the result of this query?
SELECT DATE_ADD('2024-06-01', INTERVAL 10 DAY) AS new_date;SQL
SELECT DATE_ADD('2024-06-01', INTERVAL 10 DAY) AS new_date;
Attempts:
2 left
💡 Hint
DATE_ADD adds the specified interval to the given date.
✗ Incorrect
Adding 10 days to June 1, 2024 results in June 11, 2024.
📝 Syntax
advanced2:00remaining
Identify the syntax error in DATE_ADD usage
Which option contains a syntax error in using DATE_ADD to add 3 months to '2024-01-01'?
Attempts:
2 left
💡 Hint
Check spacing between the number and the unit in INTERVAL.
✗ Incorrect
Option A misses a space between 3 and MONTH, causing a syntax error.
❓ query_result
advanced1:30remaining
Calculate difference in days with reversed dates
What is the output of this query?
SELECT DATEDIFF('2024-06-01', '2024-06-10') AS days_diff;SQL
SELECT DATEDIFF('2024-06-01', '2024-06-10') AS days_diff;
Attempts:
2 left
💡 Hint
DATEDIFF returns positive if first date is later, negative if earlier.
✗ Incorrect
Since June 1 is before June 10, the difference is negative 9 days.
🧠 Conceptual
expert2:30remaining
Understanding DATE_ADD with mixed intervals
Which option correctly adds 1 year, 2 months, and 10 days to '2023-01-01' using DATE_ADD?
Attempts:
2 left
💡 Hint
DATE_ADD only accepts one interval at a time; chaining is needed for multiple intervals.
✗ Incorrect
Option C chains DATE_ADD calls to add each interval step by step, which is valid.