STR_ TO_ DATE
On this page
Extract datetime value from input string according to a specified format.
Syntax
STR_TO_DATE (str, format)
Arguments
-
str: a valid date, datetime, or time, formatted according to the specified format string
-
format: a string containing format symbols
See DATE_
Return Type
String
Examples
SELECT STR_TO_DATE('March 3rd, 2015', '%M %D, %Y');
+---------------------------------------------+
| STR_TO_DATE('March 3rd, 2015', '%M %D, %Y') |
+---------------------------------------------+
| 2015-03-03 |
+---------------------------------------------+
SELECT STR_TO_DATE('2015-03-03 11:37:07', '%Y-%m-%d %h:%i:%s');
+---------------------------------------------------------+
| STR_TO_DATE('2015-03-03 11:37:07', '%Y-%m-%d %h:%i:%s') |
+---------------------------------------------------------+
| 2015-03-03 11:37:07 |
+---------------------------------------------------------+
SELECT STR_TO_DATE('Tuesday, the 3rd day of March in that remarkable year 2015', '%W, the %D day of %M in that remarkable year %Y') AS florid;
+------------+
| florid |
+------------+
| 2015-03-03 |
+------------+
Last modified: May 31, 2023