I have a datetime
column in MySQL.
How can I convert it to the display as mm/dd/yy H:M (AM/PM) using PHP?
You can also have your query return the time as a Unix timestamp. That would get rid of the need to call strtotime()
and make things a bit less intensive on the PHP side...
select UNIX_TIMESTAMP(timsstamp) as unixtime from the_table where id = 1234;
Then in PHP just use the date()
function to format it whichever way you'd like.
unixtime);
?>
or
unixtime);
?>
I like this approach as opposed to using MySQL's DATE_FORMAT
function, because it allows you to reuse the same query to grab the data and allows you to alter the formatting in PHP.
It's annoying to have two different queries just to change the way the date looks in the UI.