Convert MySQL Timestamp into a Nicer-looking Date Format for PHP

After spending 20 minutes searching online for a way to convert the date stored into MySQL into a human-readable format in php, I thought I would share my solution with the world.

Assuming you’re already doing a foreach or a loop to pull your MySQL variable (in this case, the ($row['timestamp']) below), use the following code:

$date = strtotime($row['timestamp']);
$date = date(‘n/d/Y, g:ia’, $date);
echo $date;

Hopefully that will save sometime time.

This entry was posted in Photos. Bookmark the permalink.

One Response to Convert MySQL Timestamp into a Nicer-looking Date Format for PHP

  1. Gerard says:

    You could format it in the query using the date_format function. This site shows you how to format the date mysql format date . com

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>