Professional Documents
Culture Documents
MySQLDATE_FORMAT()Function
MySQLDateFunctions
DefinitionandUsage
TheDATE_FORMAT()functionisusedtodisplaydate/timedataindifferentformats.
Syntax
DATE_FORMAT(date,format)
Wheredateisavaliddateandformatspecifiestheoutputformatforthedate/time.
Theformatsthatcanbeusedare:
Format
Description
%a
Abbreviatedweekdayname(SunSat)
%b
Abbreviatedmonthname(JanDec)
%c
Month,numeric(012)
%D
DayofmonthwithEnglishsuffix(0th,1st,2nd,3rd,)
%d
Dayofmonth,numeric(0031)
%e
Dayofmonth,numeric(031)
%f
Microseconds(000000999999)
%H
Hour(0023)
%h
Hour(0112)
%I
Hour(0112)
%i
Minutes,numeric(0059)
%j
Dayofyear(001366)
%k
SQL
Hour(023)
%l
Hour(112)
%M
Monthname(JanuaryDecember)
%m
Month,numeric(0012)
%p
AMorPM
%r
Time,12hour(hh:mm:ssfollowedbyAMorPM)
%S
Seconds(0059)
%s
Seconds(0059)
%T
Time,24hour(hh:mm:ss)
%U
Week(0053)whereSundayisthefirstdayofweek
%u
Week(0053)whereMondayisthefirstdayofweek
%V
Week(0153)whereSundayisthefirstdayofweek,usedwith%X
%v
Week(0153)whereMondayisthefirstdayofweek,usedwith%x
%W
Weekdayname(SundaySaturday)
%w
Dayoftheweek(0=Sunday,6=Saturday)
%X
YearfortheweekwhereSundayisthefirstdayofweek,fourdigits,used
with%V
%x
YearfortheweekwhereMondayisthefirstdayofweek,fourdigits,used
with%v
%Y
Year,numeric,fourdigits
%y
Year,numeric,twodigits