MySQL STR_TO_DATE Function

MySQL STR_TO_DATE function is a Date Function, 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 the STR_TO_DATE() Function in MySQL is as shown below:

STR_TO_DATE(string_expression, format);

MySQL STR_TO_DATE Example

Here, We used the STR_TO_DATE function 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 Function example of this STR_TO_DATE function.

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