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.
Assume that the current time is 2023-08-14 16:59.
The value 2023-08-14 04:59:15.997 is returned.
select date_format(from_utc_timestamp(getdate(), 'UTC'),'yyyy-MM-dd hh:mm:ss.SSS');
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')