Outdated Version

You are viewing an older version of this section. View current production version.

STR_TO_DATE

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