Challenge - 5 Problems
STR_TO_DATE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Parsing date with STR_TO_DATE function
What is the output of this query?
SELECT STR_TO_DATE('2024-06-15', '%Y-%m-%d') AS parsed_date;MySQL
SELECT STR_TO_DATE('2024-06-15', '%Y-%m-%d') AS parsed_date;
Attempts:
2 left
💡 Hint
Check the format string matches the input date format exactly.
✗ Incorrect
STR_TO_DATE converts the string '2024-06-15' to a date using the format '%Y-%m-%d'. The result is a DATETIME with time set to 00:00:00.
❓ query_result
intermediate1:30remaining
Parsing date with incorrect format string
What is the output of this query?
SELECT STR_TO_DATE('15/06/2024', '%Y-%m-%d') AS parsed_date;MySQL
SELECT STR_TO_DATE('15/06/2024', '%Y-%m-%d') AS parsed_date;
Attempts:
2 left
💡 Hint
The format string does not match the input string format.
✗ Incorrect
The input string '15/06/2024' does not match the format '%Y-%m-%d', so STR_TO_DATE returns NULL.
📝 Syntax
advanced1:30remaining
Identify the syntax error in STR_TO_DATE usage
Which option contains a syntax error in using STR_TO_DATE?
Attempts:
2 left
💡 Hint
Look for missing parentheses or incomplete function calls.
✗ Incorrect
Option D is missing the closing parenthesis for the STR_TO_DATE function, causing a syntax error.
❓ query_result
advanced1:30remaining
Parsing datetime with STR_TO_DATE including time
What is the output of this query?
SELECT STR_TO_DATE('15-06-2024 14:30:00', '%d-%m-%Y %H:%i:%s') AS parsed_datetime;MySQL
SELECT STR_TO_DATE('15-06-2024 14:30:00', '%d-%m-%Y %H:%i:%s') AS parsed_datetime;
Attempts:
2 left
💡 Hint
Check the format string carefully matches the input including time parts.
✗ Incorrect
The input string matches the format string exactly, so STR_TO_DATE returns the datetime '2024-06-15 14:30:00'.
🧠 Conceptual
expert2:00remaining
Understanding STR_TO_DATE behavior with invalid date parts
What will STR_TO_DATE return when parsing this string?
SELECT STR_TO_DATE('2024-13-40', '%Y-%m-%d') AS result;MySQL
SELECT STR_TO_DATE('2024-13-40', '%Y-%m-%d') AS result;
Attempts:
2 left
💡 Hint
STR_TO_DATE returns NULL for invalid date components like month >12 or invalid days.
✗ Incorrect
The input '2024-13-40' has invalid month 13 and day 40, so STR_TO_DATE returns NULL.