Home >Database >Mysql Tutorial >How can we use MySQL function STR_TO_DATE(Column, '%input_format')?

How can we use MySQL function STR_TO_DATE(Column, '%input_format')?

王林
王林forward
2023-09-06 14:57:03836browse

我们如何使用 MySQL 函数 STR_TO_DATE(Column, ‘%input_format’)?

STR_TO_DATE() function converts a string value into a datetime value, and it will format the string according to a specific format. Both string values ​​and format strings must be passed as arguments to the function. Following is the syntax of STR_TO_DATE() function.

STR_TO_DATE(string, format)

The string here is the string value that needs to be converted to a date and time value, and the format is the specified date format.

The following example will return a valid date from the given string according to the specified format.

mysql> Select STR_TO_DATE('20172810', '%Y%d%m');
+-----------------------------------+
| STR_TO_DATE('20172810', '%Y%d%m') |
+-----------------------------------+
| 2017-10-28                        |
+-----------------------------------+
1 row in set (0.00 sec)

The above is the detailed content of How can we use MySQL function STR_TO_DATE(Column, '%input_format')?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete