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

The format 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. +---------------------------------------------------------+
  7. mysql> select str_to_date('2014-12-21 12:34%3A56', '%Y-%m-%d %H:%i%%3A%s');
  8. +--------------------------------------------------------------+
  9. | str_to_date('2014-12-21 12:34%3A56', '%Y-%m-%d %H:%i%%3A%s') |
  10. +--------------------------------------------------------------+
  11. | 2014-12-21 12:34:56 |
  12. +--------------------------------------------------------------+
  13. mysql> select str_to_date('200442 Monday', '%X%V %W');
  14. +-----------------------------------------+
  15. | str_to_date('200442 Monday', '%X%V %W') |
  16. +-----------------------------------------+
  17. | 2004-10-18 |
  18. +-----------------------------------------+
  19. mysql> select str_to_date("2020-09-01", "%Y-%m-%d %H:%i:%s");
  20. +------------------------------------------------+
  21. | str_to_date('2020-09-01', '%Y-%m-%d %H:%i:%s') |
  22. +------------------------------------------------+
  23. | 2020-09-01 00:00:00 |
  24. +------------------------------------------------+
  25. 1 row in set (0.01 sec)

keyword

  1. STR_TO_DATE,STR,TO,DATE