When I make projects on my website, I’ve saved the time and date that I made them on in MySQL as ‘2012-02-27 12:32:36’ format.
How can I get this to display as:
“February 27, 2012 12:32 p.m.”?
I’ve looked at other date formatting on PHP and read on the PHP website, but all of the functions they provide don’t seem to be for grabbing a date in the format that I’ve saved it in.
First, convert the
MySQL DateTimestring you have into aDateTimeobject by usingDateTime::createFromFormat()Then, simply call
DateTime->format()with the desired format string:You can also use the MySQL
UNIX_TIMESTAMP()date function (to extract a unix timestamp compatible withdate()) or usestrtotime(), however note that these methods do not support dates after January 19, 2038 on 32-bit systems due to overflow (the two methods do not support PHP’s automatic number variables promotion).