0
0
MySQLquery~5 mins

STR_TO_DATE parsing in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the MySQL function STR_TO_DATE do?
It converts a string into a date or datetime value based on the specified format.
Click to reveal answer
beginner
Which format specifier in STR_TO_DATE represents a 4-digit year?
%Y represents a 4-digit year, like 2024.
Click to reveal answer
beginner
How would you parse the string '31-12-2023' into a date using STR_TO_DATE?
Use STR_TO_DATE('31-12-2023', '%d-%m-%Y') to convert it to a date.
Click to reveal answer
intermediate
What happens if the string format does not match the STR_TO_DATE format?
The function returns NULL because it cannot parse the string correctly.
Click to reveal answer
beginner
Which format specifier would you use to parse hours in 24-hour format?
%H is used to parse hours in 24-hour format (00 to 23).
Click to reveal answer
What does STR_TO_DATE('2024-06-15', '%Y-%m-%d') return?
AAn error
BA string '2024-06-15'
CNULL
DA date value representing June 15, 2024
Which format specifier parses the month as a number with leading zero?
A%d
B%M
C%m
D%y
What will STR_TO_DATE('15/06/24', '%d/%m/%Y') return?
ANULL
BJune 15, 2024
CJune 15, 0024
DAn error
How do you parse a time string like '14:30:00' using STR_TO_DATE?
ASTR_TO_DATE('14:30:00', '%h:%m:%s')
BSTR_TO_DATE('14:30:00', '%H:%i:%s')
CSTR_TO_DATE('14:30:00', '%I:%M:%S')
DSTR_TO_DATE('14:30:00', '%H-%i-%s')
If STR_TO_DATE returns NULL, what is the most likely cause?
AThe string does not match the format
BThe string is empty
CThe function is deprecated
DThe database is offline
Explain how STR_TO_DATE works and why the format string is important.
Think about how you read a date written in different styles.
You got /3 concepts.
    List common format specifiers used in STR_TO_DATE for date and time.
    Remember the parts of a date and time you usually see.
    You got /6 concepts.