This function is used to convert a date into a string based on the format specified by format.
date_format(string date, string format)
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
date |
Yes |
DATE or STRING |
Date to be converted The following formats are supported:
|
format |
Yes |
STRING |
Format, based on which the date is converted The value is a combination of the time unit (year, month, day, hour, minute, and second) and any character.
|
The return value is of the STRING type.
The value 2023-08-14 is returned.
select date_format('2023-08-14','yyyy-MM-dd');
The value 2023-08 is returned.
select date_format('2023-08-14','yyyy-MM')
The value 20230814 is returned.
select date_format('2023-08-14','yyyyMMdd')