MySQL STR_TO_DATE function is a Date method, which acts as an inverse of DATE_FORMAT function. This MySQL STR_TO_DATE function takes a string as an input and converts the string to Date or DateTime or Time values based on the format given by the user. The basic syntax of it is as shown below:

STR_TO_DATE(string_expression, format);


Here, We used the STR_TO_DATE to convert the different string formats to Date. For this MySQL query, we are using %d %m and %Y formats.

SELECT STR_TO_DATE('31 12 2019', '%d %m %Y');

SELECT STR_TO_DATE('31,12,2019', '%d,%m,%Y');

SELECT STR_TO_DATE('12,2019,31', '%m,%Y,%d');
MySQL STR_TO_DATE Function 1

This is an another Date method example of this one with different formats.

SELECT STR_TO_DATE('12 Jan, 2019', '%d %b, %Y');

SELECT STR_TO_DATE('2nd Jan, 2019', '%D %b, %Y');

SELECT STR_TO_DATE('2nd January, 2019', '%D %M, %Y');
MySQL STR_TO_DATE Function 2