Formatting MySQL datetime with PHP
Hello again, another of my posts of information skimmed off the top of the vast information pile that is my day! These posts are not just for the benefit of anyone who reads them but also for me. I come across so many small tips and methods here and there that I just want to keep a record of them! This post is about formatting a mysql datetime field with php.
You may need, as i did, to have a time stamp on an invoice or some sort of customer oriented output. You could put the raw data from the database which would look something like:
This is ok but not too user friendly in my opinion. So you can use the following php to make things a bit nicer:
$date = strtotime($row->entrydate); $final_date = date("F j, Y, g:i a", $date);
Which would give us an output like this:
September 3rd 2010 12:05:01 PM