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 20 %d 20
Day of month without leading zero j 20 %e 20
Day of month with english ordinal suffix jS 20th %D 20th
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 19 %j 020 PHP 0-365, MySQL 001-366


Month of year with leading zero m 01 %m 01
Month of year without leading zero n 1 %c 1
Month name F January %M January
Month name abbreviated M Jan %b Jan


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


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


Minute with leading zero i 47 %i 47


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