Skip to content

DATE_FORMAT

DATE_FORMAT(timestamp_val, literal_format_string)

Converts a timestamp value to a String value given a scalar format string.

Recognized formatting characters:

%i Minutes, zero padded (00 to 59) %M Full month name (January to December) %r Time in format in the format (hh:mm:ss AM/PM) %s Seconds, zero padded (00 to 59) %T Time in format in the format (hh:mm:ss) %T Time in format in the format (hh:mm:ss) %u week of year, where monday is the first day of the week(00 to 53) %a Abbreviated weekday name (sun-sat) %b Abbreviated month name (jan-dec) %f Microseconds, left padded with 0's, (000000 to 999999) %H Hour, zero padded (00 to 23) %j Day Of Year, left padded with 0's (001 to 366) %m Month number (00 to 12) %p AM or PM, depending on the time of day %d Day of month, zero padded (01 to 31) %Y Year as a 4 digit value %y Year as a 2 digit value, zero padded (00 to 99) %U Week of year, where Sunday is the first day of the week (00 to 53) %S Seconds, zero padded (00 to 59)

For example:

DATE_FORMAT(Timestamp '2020-01-12', '%Y %m %d') =='2020 01 12'
DATE_FORMAT(Timestamp '2020-01-12 13:39:12', 'The time was %T %p. It was a %u') =='The time was 13:39:12 PM. It was a Sunday'