0%

STR_TO_DATE

STR_TO_DATE(str,format)

This is the inverse of theDATE_FORMAT()function. It takes a string str and a format string format .STR_TO_DATE()returns aDATETIMEvalue if the format string contains both date and time parts, or aDATEorTIMEvalue if the string contains only date or time parts. If the date, time, or datetime value extracted from str is illegal,STR_TO_DATE()returnsNULLand produces a warning.

The server scans str attempting to match format to it. The format string can contain literal characters and format specifiers beginning with%. Literal characters in format must match literally in str . Format specifiers in format must match a date or time part in str . For the specifiers that can be used in format, see theDATE_FORMAT()function description.

1
2
3
4
mysql> SELECT STR_TO_DATE('01,5,2013','%d,%m,%Y');
-> '2013-05-01'
mysql> SELECT STR_TO_DATE('May 1, 2013','%M %d,%Y');
-> '2013-05-01