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:

  1. str: the string to be converted.
  2. format: a string specifying the date format.

Return value: A date value is returned.

原文:我正在为这个项目制定详细的计划。
重述:I am devising a detailed plan for this project.

  1. The function STR_TO_DATE(’10-05-2021′, ‘%d-%m-%Y’) will return the date value: 2021-05-10.
  2. The function STR_TO_DATE(‘2021/05/10’, ‘%Y/%m/%d’) returns the date value: 2021-05-10.

Things to note:

  1. The string of the date format must match the format parameter, otherwise NULL will be returned.
  2. 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.
  3. 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.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds