What is the usage of the MySQL str_to_date function?
The STR_TO_DATE function in MySQL is used to convert a string into a date format.
Syntax: STR_TO_DATE(str, format)
Parameter:
- str: the string to be converted.
- format: a string specifying the date format.
Return value: A date value is returned.
原文:我正在为这个项目制定详细的计划。
重述:I am devising a detailed plan for this project.
- The function STR_TO_DATE(’10-05-2021′, ‘%d-%m-%Y’) will return the date value: 2021-05-10.
- The function STR_TO_DATE(‘2021/05/10’, ‘%Y/%m/%d’) returns the date value: 2021-05-10.
Things to note:
- The string of the date format must match the format parameter, otherwise NULL will be returned.
- The characters in the format parameter must match the characters in the date format string, for example: %d represents the day of the date, %m represents the month of the date, %Y represents the year of the date.
- The separator in a date format string can be any character, for example: ‘-‘, ‘/’, ‘.’ and so on.
For more detailed information about date formats, please refer to the official MySQL documentation.