0
0
MySQLquery~10 mins

DATE_ADD and DATE_SUB in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add 7 days to the current date.

MySQL
SELECT DATE_ADD(CURDATE(), INTERVAL [1] DAY);
Drag options to blanks, or click blank then click option'
A7
B1
C30
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong interval unit like MONTH instead of DAY.
Forgetting to specify INTERVAL keyword.
2fill in blank
medium

Complete the code to subtract 3 months from the date '2024-06-15'.

MySQL
SELECT DATE_SUB('2024-06-15', INTERVAL [1] MONTH);
Drag options to blanks, or click blank then click option'
A1
B12
C6
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using DATE_ADD instead of DATE_SUB for subtraction.
Using DAY instead of MONTH as interval unit.
3fill in blank
hard

Fix the error in the code to add 10 hours to the current timestamp.

MySQL
SELECT DATE_ADD(NOW(), INTERVAL [1] HOUR);
Drag options to blanks, or click blank then click option'
A10
B'10'
Chour
DHOURS
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number inside quotes making it a string.
Using plural units like HOURS which is invalid.
4fill in blank
hard

Fill both blanks to subtract 15 days and add 2 weeks to '2024-01-01'.

MySQL
SELECT DATE_ADD(DATE_SUB('2024-01-01', INTERVAL [1] DAY), INTERVAL [2] WEEK);
Drag options to blanks, or click blank then click option'
A15
B10
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up days and weeks values.
Using wrong interval units.
5fill in blank
hard

Fill all three blanks to add 1 year, subtract 6 months, and add 10 days to '2023-03-10'.

MySQL
SELECT DATE_ADD(DATE_SUB(DATE_ADD('2023-03-10', INTERVAL [1] YEAR), INTERVAL [2] MONTH), INTERVAL [3] DAY);
Drag options to blanks, or click blank then click option'
A1
B6
C10
D12
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of intervals.
Using incorrect numbers for intervals.