How to Display MySQL Dates in Other Formats using PHP

MySQL stores dates in the format YYYY-MM-DD… which is great, it’s consistent and easy to understand—If you happen to be a computer. Unfortunately, this format is rather confusing for humans, especially for humans which may be trying to communicate with individuals who read dates differently. For example, those of us in the US usually record the 10th of May in the year 2016 as 05/10/2016 whereas individuals in other countries often record the same date as 10/05/2016, causing considerable confusion in communication.

So what do we do to solve this? When in doubt, write it out! Here’s how to take a date retrieved from a MySQL database by PHP and convert it to an international human-friendly format.

We’ll first assume that you have retrieved your data into array $myrow. Say the date stored in MySQL is 2016-01-04. Here’s how to display it in various forms. Precede each of these by echo or print, whichever is appropriate for your application. All of these can be modified as needed by using the various formatting characters as described in the PHP: date manual.

Desired Text Code
January 04, 2016 date("F d, Y",strtotime($myrow['date']));
Monday, January 04, 2016 date("l, F d, Y",strtotime($myrow['date']));
Jan 04, 2016 date("M d, Y",strtotime($myrow['date']));
04 January 2016 date("d F Y",strtotime($myrow['date']));
04 Jan 2016 date("d M Y",strtotime($myrow['date']));
Mon, 04 Jan 2016 date("D, d M Y",strtotime($myrow['date']));
Monday, the 4th of January, 2016 date("l",strtotime($myrow['date'])) . ", the " . date("jS",strtotime($myrow['date'])) . " of " . date("F, Y",strtotime($myrow['date']));

Search Help: Visitors seeking this information might use the following search strings: “How do I display MySQL dates in other formats?”, “MySQL dates PHP”, “MySQL datestamp field”, “MySQL datestamp format”, “MySQL PHP date format”, “”MySQL PHP date conversion”, “Convert MySQL date in PHP”.