STR_TO_DATE

STR_TO_DATE is a MySQL function used to convert a string into a date and time value according to a specified format.

STR_TO_DATE(string, format)

  • string: This parameter represents the date string to be converted. It is the source value that SQL will parse to create a date value.
  • format: A string value representing the format to be used for the conversion. The format string consists of one or more format specifiers that define the format of the date string. These specifiers can represent elements such as day, month, year, hour, minute, and second.

Example

SELECT STR_TO_DATE('15,03,2020', '%d,%m,%Y');

Output

2020-03-15

Explanation

The STR_TO_DATE() function takes in two parameter strings: The first string is the date string and the second string is the format string. In the above example, STR_TO_DATE() function converts a string date into a DATE data type according to the format speicified (‘%d,%m,%Y’ in this case). This format string ‘%d,%m,%Y’ indicates that day should be interpreted as two digits, the month as two digits, and the year as four digits, separated by commas.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.