0
0
MySQLquery~20 mins

STR_TO_DATE parsing in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
STR_TO_DATE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1: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;
A2024-06-15 00:00:00
BNULL
C2024-15-06 00:00:00
DSyntax error
Attempts:
2 left
💡 Hint
Check the format string matches the input date format exactly.
query_result
intermediate
1: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;
A2024-06-15 00:00:00
BNULL
C15/06/2024
DSyntax error
Attempts:
2 left
💡 Hint
The format string does not match the input string format.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in STR_TO_DATE usage
Which option contains a syntax error in using STR_TO_DATE?
ASELECT STR_TO_DATE('2024-06-15', '%Y-%m-%d') AS date_val;
BSELECT STR_TO_DATE('06-15-2024', '%m-%d-%Y') AS date_val;
CSELECT STR_TO_DATE('2024/06/15', '%Y/%m/%d') AS date_val;
DSELECT STR_TO_DATE('2024-06-15', '%Y-%m-%d'
Attempts:
2 left
💡 Hint
Look for missing parentheses or incomplete function calls.
query_result
advanced
1: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;
ANULL
B15-06-2024 14:30:00
C2024-06-15 14:30:00
DSyntax error
Attempts:
2 left
💡 Hint
Check the format string carefully matches the input including time parts.
🧠 Conceptual
expert
2: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;
ANULL
B2024-13-40 00:00:00
C2024-01-09 00:00:00
DSyntax error
Attempts:
2 left
💡 Hint
STR_TO_DATE returns NULL for invalid date components like month >12 or invalid days.