Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.32 KB

File metadata and controls

42 lines (31 loc) · 1.32 KB

str_to_date

description

Syntax

DATETIME STR_TO_DATE(VARCHAR str, VARCHAR format)

通过format指定的方式将str转化为DATE类型,如果转化结果不对返回NULL

支持的format格式与 date_format 一致

example

MySQL > select str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s');
+---------------------------------------------------------+
| str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s') |
+---------------------------------------------------------+
| 2014-12-21 12:34:56                                     |
+---------------------------------------------------------+

MySQL > select str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s');
+--------------------------------------------------------------+
| str_to_date('2014-12-21 12:34%3A56', '%Y-%m-%d %H:%i:%s') |
+--------------------------------------------------------------+
| 2014-12-21 12:34:56                                          |
+--------------------------------------------------------------+

MySQL > select str_to_date('200442 Monday', '%X%V %W');
+-----------------------------------------+
| str_to_date('200442 Monday', '%X%V %W') |
+-----------------------------------------+
| 2004-10-18                              |
+-----------------------------------------+

keyword

STR_TO_DATE,STR,TO,DATE