Product Solutions Support
Try MemSQL

STR_TO_DATE

Extract datetime value from input string according to a specified format.

STR_TO_DATE (str, format)

Arguments

See DATE_FROMAT for a description of format symbols.

Return Type

A date, datetime, or time object depends on which fields present in the format string.

Examples

memsql> select str_to_date('March 3rd, 2015', '%M %D, %Y');
+---------------------------------------------+
| str_to_date('March 3rd, 2015', '%M %D, %Y') |
+---------------------------------------------+
| 2015-03-03                                  |
+---------------------------------------------+

memsql> 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                                     |
+---------------------------------------------------------+

memsql> 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 |
+------------+
Was this article useful?