0
0
MySQLquery~20 mins

Date and time types in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Date and Time Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this query?
Consider the table events with a column event_date of type DATE. What will this query return?

SELECT event_date + INTERVAL 1 DAY AS next_day FROM events WHERE event_date = '2024-06-15';
MySQL
SELECT event_date + INTERVAL 1 DAY AS next_day FROM events WHERE event_date = '2024-06-15';
AThe original event_date values without change
BA syntax error because INTERVAL cannot be added this way
CNULL values for all rows
DA list of dates, each one day after '2024-06-15' for matching rows
Attempts:
2 left
💡 Hint
Think about how MySQL adds intervals to date values.
🧠 Conceptual
intermediate
1:30remaining
Which MySQL data type stores both date and time?
You want to store a value that includes both the date and the time of an event. Which MySQL data type should you use?
ADATETIME
BTIME
CDATE
DYEAR
Attempts:
2 left
💡 Hint
Think about which type includes both parts, date and time.
📝 Syntax
advanced
2:00remaining
Which query correctly extracts the year from a DATETIME column?
Given a table orders with a created_at column of type DATETIME, which query correctly returns the year part of created_at?
ASELECT created_at->year FROM orders;
BSELECT EXTRACT(YEAR created_at) FROM orders;
CSELECT YEAR(created_at) FROM orders;
DSELECT DATEPART(year, created_at) FROM orders;
Attempts:
2 left
💡 Hint
MySQL has a built-in function named YEAR().
optimization
advanced
2:30remaining
How to optimize a query filtering by date only on a DATETIME column?
You have a large table logs with a created_at DATETIME column. You want to find all rows from '2024-06-01' ignoring time. Which query is optimized for using an index on created_at?
ASELECT * FROM logs WHERE DATE(created_at) = '2024-06-01';
BSELECT * FROM logs WHERE created_at >= '2024-06-01 00:00:00' AND created_at < '2024-06-02 00:00:00';
CSELECT * FROM logs WHERE created_at LIKE '2024-06-01%';
DSELECT * FROM logs WHERE created_at BETWEEN '2024-06-01 00:00:00' AND '2024-06-01 23:59:59';
Attempts:
2 left
💡 Hint
Functions on columns can prevent index use.
🔧 Debug
expert
3:00remaining
Why does this query return no rows?
Given a table appointments with a start_time column of type TIME, why does this query return no rows?

SELECT * FROM appointments WHERE start_time = '09:00';
MySQL
SELECT * FROM appointments WHERE start_time = '09:00';
ABecause TIME values require seconds, so '09:00' is invalid and matches nothing
BBecause the column stores DATETIME, not TIME, so comparison fails
CBecause '09:00' is interpreted as a string and not converted to TIME
DBecause the query syntax is incorrect and causes an error
Attempts:
2 left
💡 Hint
Check the format expected for TIME values in MySQL.