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 47 %j 048 PHP 0-365, MySQL 001-366

Month

Month of year with leading zero m 02 %m 02
Month of year without leading zero n 2 %c 2
Month name F February %M February
Month name abbreviated M Feb %b Feb

Year

Year Y 2019 %Y 2019
Year abbreviated y 19 %y 19

Hour

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

Minute

Minute with leading zero i 40 %i 40

Second

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

Other

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