PHP & MySQL Date Format Reference

Title PHP PHP example MySQL MySQL example Notes
date($format, [$timestamp]) DATE_FORMAT(date, format)

Day & Date

Day of month with leading zero d 21 %d 21
Day of month without leading zero j 21 %e 21
Day of month with english ordinal suffix jS 21st %D 21st
Day name l Saturday %W Saturday
Day name abbreviated D Sat %a Sat
Day number in current week w 6 %w 6 0-Sunday, 6-Saturday
Day number in current year z 293 %j 294 PHP 0-365, MySQL 001-366


Month of year with leading zero m 10 %m 10
Month of year without leading zero n 10 %c 10
Month name F October %M October
Month name abbreviated M Oct %b Oct


Year Y 2017 %Y 2017
Year abbreviated y 17 %y 17


24 Hour with leading zero H 18 %H 18
24 Hour without leading zero G 18 %k 18
12 Hour with leading zero h 06 %h 06 %I also works in MySQL
12 Hour without leading zero g 6 %l 6
AM or PM A PM %p PM 'a' can also be used in php for lowercase result.


Minute with leading zero i 31 %i 31


Seconds with leading zero s 56 %s 56 %S also works in MySQL


Microseconds u 000000 %f 000000
Leap year L 0 '1' if leap year, '0' if not. No MySql alternative.
Documentation - date() - date_format()