0
0
MySQLquery~10 mins

Date and time types 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 create a column that stores date values only.

MySQL
CREATE TABLE events (event_date [1]);
Drag options to blanks, or click blank then click option'
ADATE
BDATETIME
CTIMESTAMP
DTIME
Attempts:
3 left
💡 Hint
Common Mistakes
Using DATETIME when only date is needed.
Using TIME which stores only time, not date.
2fill in blank
medium

Complete the code to insert the current date and time into a DATETIME column.

MySQL
INSERT INTO logs (log_time) VALUES ([1]());
Drag options to blanks, or click blank then click option'
ANOW
BCURDATE
CCURRENT_DATE
DSYSDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using CURDATE() which returns only the date.
Using CURRENT_DATE which is similar to CURDATE().
3fill in blank
hard

Fix the error in the query to select rows where the time is after 14:00:00.

MySQL
SELECT * FROM shifts WHERE shift_start > '[1]';
Drag options to blanks, or click blank then click option'
A14:00
B14
C2 PM
D14:00:00
Attempts:
3 left
💡 Hint
Common Mistakes
Using '14:00' without seconds.
Using '2 PM' which is not a valid MySQL time format.
4fill in blank
hard

Fill both blanks to create a table with a TIMESTAMP column that defaults to the current timestamp.

MySQL
CREATE TABLE user_logins (login_time [1] DEFAULT [2]);
Drag options to blanks, or click blank then click option'
ATIMESTAMP
BCURRENT_TIMESTAMP
CNOW()
DDATETIME
Attempts:
3 left
💡 Hint
Common Mistakes
Using DATETIME with CURRENT_TIMESTAMP default (not always supported).
Using NOW() as default which is a function call, not a constant.
5fill in blank
hard

Fill all three blanks to select rows where the date is after 2023-01-01 and time is before 18:00:00.

MySQL
SELECT * FROM appointments WHERE appointment_date > '[1]' AND appointment_time < '[2]' AND appointment_date < '[3]';
Drag options to blanks, or click blank then click option'
A2023-01-01
B18:00:00
C2024-01-01
D17:00:00
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect date or time formats.
Mixing up the order of conditions.