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 18 %d 18
Day of month without leading zero j 18 %e 18
Day of month with english ordinal suffix jS 18th %D 18th
Day name l Wednesday %W Wednesday
Day name abbreviated D Wed %a Wed
Day number in current week w 3 %w 3 0-Sunday, 6-Saturday
Day number in current year z 198 %j 199 PHP 0-365, MySQL 001-366


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 Y 2018 %Y 2018
Year abbreviated y 18 %y 18


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


Minute with leading zero i 37 %i 37


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