Function Reference

DATE_FORMAT

PostgreSQL equivalent:

Formats a date as a string according to the given format.

MySQL 8.1
DATE_FORMAT(datetime, format)

Parameters

datetimeDATETIME
Date or datetime
formatVARCHAR
Format string with specifiers from the table

Return value

A string; month and weekday names are in English by default; NULL if any argument is NULL

Examples

Date and time in DD.MM.YYYY HH:MM format

MySQL 8.1
SELECT DATE_FORMAT('2022-06-16 16:37:03', '%d.%m.%Y %H:%i') AS formatted;
formatted
16.06.2022 16:37

Weekday and month names

MySQL 8.1
SELECT DATE_FORMAT('2022-06-16 16:37:03', '%W, %M %D %Y, %h:%i %p') AS formatted;
formatted
Thursday, June 16th 2022, 04:37 PM

Birthdays in a custom format

MySQL 8.1
SELECT member_name,
	DATE_FORMAT(birthday, '%d.%m.%Y') AS birth_date
FROM FamilyMembers;
member_namebirth_date
Headley Quincey13.05.1960
Flavia Quincey16.02.1963
Andie Quincey05.06.1983
Lela Quincey07.06.1985
Annie Quincey10.04.1988
Ernest Forrest11.09.1961
Constance Forrest06.09.1968
Wednesday Addams13.01.2005

Details

SpecifierOutput
%aAbbreviated weekday name (Sun..Sat)
%bAbbreviated month name (Jan..Dec)
%cMonth number without a leading zero (0..12)
%DDay of the month with an English suffix (0th, 1st, 2nd, 3rd…)
%dDay of the month with a leading zero (00..31)
%eDay of the month without a leading zero (0..31)
%fMicroseconds (000000..999999)
%HHour with a leading zero (00..23)
%hHour in 12-hour format with a leading zero (01..12)
%ISame as %h (01..12)
%iMinutes with a leading zero (00..59)
%jDay of the year with leading zeros (001..366)
%kHour without a leading zero (0..23)
%lHour in 12-hour format without a leading zero (1..12)
%MMonth name (January..December)
%mMonth number with a leading zero (00..12)
%pAM or PM
%rTime in 12-hour format (hh:mm:ss AM or PM)
%SSeconds with a leading zero (00..59)
%sSame as %S (00..59)
%TTime in 24-hour format (hh:mm:ss)
%UWeek (00..53), Sunday is the first day, as WEEK with mode 0
%uWeek (00..53), Monday is the first day, as WEEK with mode 1
%VWeek (01..53), Sunday is the first day, as WEEK with mode 2; used with %X
%vWeek (01..53), Monday is the first day, as WEEK with mode 3; used with %x
%WWeekday name (Sunday..Saturday)
%wWeekday number (0 is Sunday, 6 is Saturday)
%XYear of the week for %V, four digits
%xYear of the week for %v, four digits
%YYear, four digits
%yYear, two digits
%%The % character

See also