Formatting the Output of a Date – (eg. June 6. 2006)

Figured this one out when working on a client project. Needed to format the publishing date of newsflash articles that I was pulling from the database. Before I was writing a whole function to process the output but now I’ve got it down to a one liner. Here’s how I did it.

‘$row->publish_up’ when it first comes out of the db looks like this: ’2006-06-06 17:50:37′
which is standard output from the MySQL database.

Then I did this:

echo date("F jS. Y".strtotime($row->publish_up.1));

Which outputs: ‘May 5. 2009′

Leave a Reply