What is the purpose of the DATE data type in MySQL?
The DATE data type stores date values in the format 'YYYY-MM-DD', representing year, month, and day without time information.
Click to reveal answer
intermediate
How does the DATETIME type differ from the TIMESTAMP type in MySQL?
DATETIME stores date and time without timezone conversion, while TIMESTAMP stores date and time as UTC and converts to the current timezone on retrieval.
Click to reveal answer
beginner
What is the format of the TIME data type in MySQL?
TIME stores time values in the format 'HH:MM:SS', representing hours, minutes, and seconds.
Click to reveal answer
intermediate
Which MySQL date/time type would you use to store only the year and month?
MySQL does not have a specific type for only year and month; you can use DATE and ignore the day or store as a string.
Click to reveal answer
intermediate
What happens if you insert an invalid date like '2024-02-30' into a DATE column in MySQL?
MySQL will reject the invalid date or store '0000-00-00' depending on SQL mode settings, because '2024-02-30' is not a valid calendar date.
Click to reveal answer
Which MySQL data type stores both date and time without timezone conversion?
ATIME
BDATE
CDATETIME
DTIMESTAMP
✗ Incorrect
DATETIME stores date and time exactly as entered without timezone conversion.
What is the default format for the TIME data type in MySQL?
AMM-DD-YYYY
BYYYY-MM-DD
CYYYY-MM-DD HH:MM:SS
DHH:MM:SS
✗ Incorrect
TIME stores time values in 'HH:MM:SS' format.
Which MySQL data type automatically converts stored time to UTC and back to local time on retrieval?
ATIMESTAMP
BTIME
CDATE
DDATETIME
✗ Incorrect
TIMESTAMP stores values in UTC and converts to local time on retrieval.
If you want to store only a date without time, which MySQL type should you use?
ADATE
BTIME
CDATETIME
DTIMESTAMP
✗ Incorrect
DATE stores only the date part without time.
What will MySQL do if you insert '2024-02-30' into a DATE column with strict mode enabled?
AStore '0000-00-00'
BReject the insert with an error
CStore '2024-02-30' as is
DAutomatically correct to '2024-02-29'
✗ Incorrect
In strict mode, MySQL rejects invalid dates like '2024-02-30' with an error.
Explain the differences between DATE, DATETIME, and TIMESTAMP types in MySQL.
Think about what each type stores and how timezones are handled.
You got /3 concepts.
Describe how MySQL handles invalid dates when inserting into a DATE column.
Consider SQL mode settings and validation rules.
You got /3 concepts.
Practice
(1/5)
1. Which MySQL data type should you use to store only a date without time?
easy
A. DATE
B. DATETIME
C. TIME
D. TIMESTAMP
Solution
Step 1: Understand the data types
DATE stores only the date (year, month, day). DATETIME and TIMESTAMP store date and time. TIME stores only time.
Step 2: Match the requirement
Since we want to store only the date without time, DATE is the correct choice.
Final Answer:
DATE -> Option A
Quick Check:
Date only = DATE [OK]
Hint: Date only? Use DATE type [OK]
Common Mistakes:
Choosing DATETIME when only date is needed
Using TIME for date storage
Confusing TIMESTAMP with DATE
2. Which of the following is the correct syntax to declare a column named start_time that stores only time in MySQL?
easy
A. start_time TIME;
B. start_time DATE;
C. start_time DATETIME;
D. start_time TIMESTAMP;
Solution
Step 1: Identify the correct data type for time only
The TIME type stores only time values (hours, minutes, seconds).
Step 2: Check syntax correctness
Declaring a column as start_time TIME; is valid syntax in MySQL.
Final Answer:
start_time TIME; -> Option A
Quick Check:
Time only column = TIME type [OK]
Hint: Use TIME type for time-only columns [OK]
Common Mistakes:
Using DATE or DATETIME for time-only columns
Missing semicolon in declaration
Confusing TIMESTAMP with TIME
3. Given the table events with a column event_datetime DATETIME, what will the query SELECT DATE(event_datetime) FROM events WHERE event_datetime = '2024-06-15 14:30:00'; return?
medium
A. 2024-06-15 14:30:00
B. 2024-06-15
C. 14:30:00
D. Error: Invalid function
Solution
Step 1: Understand the DATE() function
The DATE() function extracts only the date part (year-month-day) from a datetime value.
Hint: DATE() extracts date part from datetime [OK]
Common Mistakes:
Expecting full datetime as output
Confusing DATE() with TIME() function
Thinking DATE() causes error
4. You wrote this query to insert a time value: INSERT INTO schedule (meeting_time) VALUES ('25:00:00'); but it gives an error. What is the problem?
medium
A. Using DATETIME instead of TIME column type
B. Missing quotes around time value
C. Time value exceeds valid hour range (0-23)
D. Incorrect table name
Solution
Step 1: Check the time value format
Valid time values must have hours between 00 and 23. '25:00:00' has 25 hours, which is invalid.
Step 2: Understand MySQL time validation
MySQL rejects time values outside the valid range, causing an error on insert.
Final Answer:
Time value exceeds valid hour range (0-23) -> Option C
Quick Check:
Hours must be 0-23 in TIME values [OK]
Hint: Hours in TIME must be 0-23 [OK]
Common Mistakes:
Assuming 25 is valid hour
Forgetting quotes around time
Confusing column type with error cause
5. You want to store the exact moment a user logs in, including date and time, and also want automatic timezone conversion to UTC. Which MySQL data type should you use?
hard
A. DATETIME
B. DATE
C. TIME
D. TIMESTAMP
Solution
Step 1: Understand the data types and timezone behavior
TIMESTAMP stores date and time and automatically converts values to UTC for storage and back to local time on retrieval. DATETIME stores date and time but does not handle timezone conversion.
Step 2: Match requirement for timezone conversion
Since automatic timezone conversion is needed, TIMESTAMP is the correct choice.
Final Answer:
TIMESTAMP -> Option D
Quick Check:
TIMESTAMP handles timezone conversion [OK]
Hint: Use TIMESTAMP for timezone-aware datetime [OK]
Common Mistakes:
Choosing DATETIME and expecting timezone conversion
Using DATE or TIME for full datetime
Ignoring timezone needs
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.