Skip to main content
Version: V1.0.0

DATE_FORMAT

Declaration

DATE_FORMAT(date, format)

Description

Outputs the date and time in the specified format. date specifies the date and time, and format specifies the output format.

The following table lists all the output formats:

FormatDescriptionFormat
%aThe English abbreviation of the day of the week.Sun..Sat
%bThe English abbreviation of the month.Jan..Dec
%cThe numeric representation of the month.1..12
%DThe English abbreviation of the day.1st..31st
%dThe numeric representation of the day.01..31
%eThe numeric representation of the day.1.. 31
%fMicroseconds.000000..999999
%HHours.00..23
%hHours.01..12
%IHours.01..12
%iMinutes.00..59
%jThe day of the year.001..366
%kHours.0..23
%lHours.0..12
%MThe English name of the month.January..December
%mThe numeric representation of the month.01..12
%pAM or PM.AM/PM
%r12-hour clock time.hh:mm:ss AM/PM
%SSeconds.00..59
%sSeconds.00..59
%T24-hour clock time.hh:mm:ss
%UThe week number in the year, with Sunday as the first day of the week.00..53
%uThe week number in the year, with Monday as the first day of the week.00..53
%VThe week number in the year, with Sunday as the first day of the week (used with %X).01..53
%vThe week number in the year, with Monday as the first day of the week (used with %x).01..53
%WThe English name of the day.Sunday..Saturday
%wThe day of the week.0=Sunday..6=Saturday
%XThe year of the week, with Sunday as the first day of the week (used with %V).
%xThe year of the week, with Monday as the first day of the week (used with %v).
%YThe four-digit year.
%yThe two-digit year.
%%A literal character, outputs a single %.

Examples

SELECT
DATE_FORMAT('2014-01-01', '%Y-%M-%d'),
DATE_FORMAT('2014-01-01', '%X-%V'),
DATE_FORMAT('2014-01-01', '%U')
\G
*************************** 1. row ***************************
DATE_FORMAT('2014-01-01', '%Y-%M-%d'): 2014-January-01
DATE_FORMAT('2014-01-01', '%X-%V'): 2013-52
DATE_FORMAT('2014-01-01', '%U'): 00
1 row in set (0.001 sec)