STR_TO_DATE
STR_TO_DATE(string, format)
Section titled “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
Section titled “Example”SELECT STR_TO_DATE('15,03,2020', '%d,%m,%Y');Output
Section titled “Output”2020-03-15Explanation
Section titled “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.