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 21 %d 21
Day of month without leading zero j 21 %e 21
Day of month with english ordinal suffix jS 21st %D 21st
Day name l Monday %W Monday
Day name abbreviated D Mon %a Mon
Day number in current week w 1 %w 1 0-Sunday, 6-Saturday
Day number in current year z 232 %j 233 PHP 0-365, MySQL 001-366

Month

Month of year with leading zero m 08 %m 08
Month of year without leading zero n 8 %c 8
Month name F August %M August
Month name abbreviated M Aug %b Aug

Year

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

Hour

24 Hour with leading zero H 03 %H 03
24 Hour without leading zero G 3 %k 3
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 AM %p AM 'a' can also be used in php for lowercase result.

Minute

Minute with leading zero i 28 %i 28

Second

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