There is a synatax errro your variable name is $hour but in last you have used $hours.
$time1 = strtotime("02:40:00");
$time2 = strtotime("34:20:00");
$diff = $time2 - $time1;
$hour = floor($diff / (60 * 60));
$minute = $diff - $hour * (60 * 60);
//$final = $hours .":".floor( $minute / 60 );
$final = $hour .":".floor( $minute / 60 );
echo $final;
You can do with a custom function like below:-
<?php
$actual_time = "34:20";
$time_to_reduce = "2:40";
function timeSubtactionFirstTime($actual_time ,$time_to_reduce){
$actual_time_array = explode(":",$actual_time);
$time_to_reduce = explode(":",$time_to_reduce);
$final_result = [];
if($actual_time_array[1] < $time_to_reduce[1]){
$actual_time_array[0] = $actual_time_array[0]-1;
$final_result[] = $actual_time_array[1]+60-$time_to_reduce[1];
}else{
$final_result[] = $actual_time_array[1]-$time_to_reduce[1];
}
$final_result[] = $actual_time_array[0]-$time_to_reduce[0];
return implode(":", array_reverse($final_result));
}
echo timeSubtactionFirstTime($actual_time ,$time_to_reduce);
Output:-https://eval.in/920129
Note:- i din't consider seconds here. a bit mor logic is reuired for that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With