Str_to_date
Description
Syntax
DATETIME STR TWO DATES (VARCHAR STR, VARCHAR format)
Convert STR to DATE type by format specified, if the conversion result does not return NULL. Note that the ‘format’ parameter specifies the format of the first parameter.
The format supported is consistent with date_format
example
1. mysql> select str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s');
2. +---------------------------------------------------------+
3. | str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s') |
4. +---------------------------------------------------------+
5. | 2014-12-21 12:34:56 |
6. +---------------------------------------------------------+
8. mysql> select str_to_date('2014-12-21 12:34%3A56', '%Y-%m-%d %H:%i%%3A%s');
9. +--------------------------------------------------------------+
10. | str_to_date('2014-12-21 12:34%3A56', '%Y-%m-%d %H:%i%%3A%s') |
11. +--------------------------------------------------------------+
12. | 2014-12-21 12:34:56 |
13. +--------------------------------------------------------------+
15. mysql> select str_to_date('200442 Monday', '%X%V %W');
16. +-----------------------------------------+
17. | str_to_date('200442 Monday', '%X%V %W') |
18. +-----------------------------------------+
19. | 2004-10-18 |
20. +-----------------------------------------+
22. mysql> select str_to_date("2020-09-01", "%Y-%m-%d %H:%i:%s");
23. +------------------------------------------------+
24. | str_to_date('2020-09-01', '%Y-%m-%d %H:%i:%s') |
25. +------------------------------------------------+
26. | 2020-09-01 00:00:00 |
27. +------------------------------------------------+
28. 1 row in set (0.01 sec)
keywords
1. STR_TO_DATE,STR,TO,DATE
