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 aDATETIME
value if the format string contains both date and time parts, or aDATE
orTIME
value if the string contains only date or time parts. If the date, time, or datetime value extracted from str is illegal,STR_TO_DATE()
returnsNULL
and 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 | mysql> SELECT STR_TO_DATE('01,5,2013','%d,%m,%Y'); |