0

I have an array with time values

 print_r($timeVal);

output:

 Array ( 
[2018-12-01] => 23:58:0 
[2018-12-02] => 23:58:0
[2018-12-03] => 23:58:0     
[2018-12-05] => 2:0:0 
)

so i want to calculate all those and get total time: correct result should be

73:54 and not 3 days 1 hours 54 minutes 0 seconds

post is not duplicate coz i viewed other posts and they show Day hour minute not just hour min

example like this :

 $sum = strtotime('00:00:00');
 $sum2=0;  
 foreach ($TimeVal as $v){

        $sum1=strtotime($v)-$sum;

        $sum2 = $sum2+$sum1;
    }

    $sum3=$sum+$sum2;
date("H:i:s",$sum3)  //this show 1:54:00
Gloytos htyqo
  • 345
  • 1
  • 3
  • 12

1 Answers1

0

Since you do not want to display your time in a 24-hour format, date() won't give you what you are looking for.

I copied your code and modified it slightly, so it does the job with the example you gave:

$sum = strtotime('00:00:00');
$sum1 = 0;
foreach ($TimeVal as $v){
    $sum1 += strtotime($v) - $sum;
}
$hours = $sum1 / 3600;
$minutes = ($hours - floor($hours)) * 60;

echo floor($hours) . ':' . round($minutes);
S. Tea
  • 121
  • 1
  • 10