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


Month of year with leading zero m 12 %m 12
Month of year without leading zero n 12 %c 12
Month name F December %M December
Month name abbreviated M Dec %b Dec


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


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


Minute with leading zero i 25 %i 25


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