[MySQL] Parse a date-time string with STR_TO_DATE()

Created on November 30, 2026

You can use STR_TO_DATE() to turn a string into a date or date-time value. Pass the input string first and its format second. In this example, the format describes both the date and time, so the result is a DATETIME.

SELECT STR_TO_DATE('2022-09-01 10:00:00', '%Y-%m-%d %H:%i:%s') AS parsed_at;
2022-09-01 10:00:00

Reference

MySQL