I am trying to identify the duration of something by finding the difference between the start time and the end time.
//bring date & time input into mysql datetime format for query
$t_start_datetime = date('Y-m-d G:i:s' ,strtotime($_POST['t_date'].' '.$_POST['t_start'].' '.$_POST['s_ampm']));
$t_end_datetime = date('Y-m-d G:i:s' ,strtotime($_POST['t_date'].' '.$_POST['t_end'].' '.$_POST['e_ampm']));
// get duration value of test by finding the difference between the start and end time.
$end_time= strtotime($_POST['t_date'].' '.$_POST['t_start'].' '.$_POST['s_ampm']);
$start_time= strtotime($_POST['t_date'].' '.$_POST['t_end'].' '.$_POST['e_ampm']);
$temp = $end_time - $start_time;
echo date('G:i:s', $end_time);
echo date('G:i:s', $start_time);
//here is the duration
echo date('G:i:s', abs($temp));
So lets say the value of start_time
was 6:00:00 and end_time
7:45:00 my duration is coming out as 2:45:00 :S
It's always an hour more than the actually difference.
What am I doing wrong? Please enlighten me.
Thanks