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


Month of year with leading zero m 06 %m 06
Month of year without leading zero n 6 %c 6
Month name F June %M June
Month name abbreviated M Jun %b Jun


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


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


Minute with leading zero i 02 %i 02


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