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!