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 15 %d 15
Day of month without leading zero j 15 %e 15
Day of month with english ordinal suffix jS 15th %D 15th
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 318 %j 319 PHP 0-365, MySQL 001-366


Month of year with leading zero m 11 %m 11
Month of year without leading zero n 11 %c 11
Month name F November %M November
Month name abbreviated M Nov %b Nov


Year Y 2018 %Y 2018
Year abbreviated y 18 %y 18


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


Minute with leading zero i 46 %i 46


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