MySQL STR_TO_DATE function is a Date method, which acts as an inverse of the DATE_FORMAT function. This MySQL STR_TO_DATE function takes a string as an input and converts the string to Date, 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);

MySQL STR_TO_DATE Function Example

Here, We used the STR_TO_DATE to convert the different string formats to Date. For this MySQL query, we use %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');
STR_TO_DATE Example 1

This is 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');

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.