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 22 %d 22
Day of month without leading zero j 22 %e 22
Day of month with english ordinal suffix jS 22nd %D 22nd
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 172 %j 173 PHP 0-365, MySQL 001-366

Month

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

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

Hour

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

Minute

Minute with leading zero i 20 %i 20

Second

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