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

MySQLMySQLi Database

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

STR_TO_DATE(string, format)

Here string is the value of string which needs to be converted to datetime value and format is the specified date format.

The following example will return valid date from given string and 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)
Updated on 30-Jan-2020 05:59:04