I am trying to add two time using strtotime.i use following code to add two time.
my expected output is 15:59:00
but it gives me 09:30:44
. so what is the problem?
Thanks in advance.
$json['time'] = "15:14";
$total_duration = "45"; //in minutes
/* convert minutes into hours-minutes */
$hours = intval($total_duration / 60);
$mins = $total_duration % 60;
$service_duration = strtotime($hours."00:00")+strtotime("00:".$mins.":00");
/* end time = total service duration + start time */
$start_time = strtotime($json['time'].":00");
echo $service_duration."--".$start_time."==";
$end_time2 = $start_time+$service_duration;
$end_time = date('H:i:s', $end_time2);echo $end_time;exit;
You can do like
$json['time'] = "15:14";
$total_duration = "45"; //in minutes
$endTime = strtotime("+".$total_duration." minutes", strtotime($json['time']));
echo date('H:i:s', $endTime);
Output:
15:59:00