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 25 %d 25
Day of month without leading zero j 25 %e 25
Day of month with english ordinal suffix jS 25th %D 25th
Day name l Thursday %W Thursday
Day name abbreviated D Thu %a Thu
Day number in current week w 4 %w 4 0-Sunday, 6-Saturday
Day number in current year z 144 %j 145 PHP 0-365, MySQL 001-366


Month of year with leading zero m 05 %m 05
Month of year without leading zero n 5 %c 5
Month name F May %M May
Month name abbreviated M May %b May


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


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


Minute with leading zero i 39 %i 39


Seconds with leading zero s 27 %s 27 %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()