Having trouble converting AM time values from MySQL fetch_array when using the PHP date() function. Not sure why the stop time below is being printed as the 7:00PM when it should be 11:00AM. Any ideas? Any help is much appreciated!
<?php
$mysql_output = array('start' => '19:00:00','stop' => '11:00:00');
$start_time = date('g:iA',$mysql_output['start']);
$stop_time = date('g:iA',$mysql_output['stop']);
echo "<p>start_time: $start_time</p>";
echo "<p>stop_time: $stop_time</p>";
?>
The result doesn’t convert the AM time correctly; should read 11:00AM for stop_time:
start_time: 7:00PM
stop_time: 7:00PM
The
date()function takes a Unix timestamp, not a string datetimestamp. You need to put a MySQL datetimestamp throughstrtotime()first.