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

Month

Month of year with leading zero m 07 %m 07
Month of year without leading zero n 7 %c 7
Month name F July %M July
Month name abbreviated M Jul %b Jul

Year

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

Hour

24 Hour with leading zero H 15 %H 15
24 Hour without leading zero G 15 %k 15
12 Hour with leading zero h 03 %h 03 %I also works in MySQL
12 Hour without leading zero g 3 %l 3
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 04 %s 04 %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()