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?
✗ Incorrect
STR_TO_DATE converts the string to a date using the format '%Y-%m-%d'.
Which format specifier parses the month as a number with leading zero?
✗ Incorrect
%m parses the month as a two-digit number (01 to 12).
What will STR_TO_DATE('15/06/24', '%d/%m/%Y') return?
✗ Incorrect
The year format '%Y' expects 4 digits, but '24' is only 2 digits, so it returns NULL.
How do you parse a time string like '14:30:00' using STR_TO_DATE?
✗ Incorrect
%H:%i:%s parses 24-hour time with minutes and seconds.
If STR_TO_DATE returns NULL, what is the most likely cause?
✗ Incorrect
STR_TO_DATE returns NULL when the input string does not match the given format.
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.