0

How to sum up time in php. For example I have this series of time duration logs:

00:10:00
00:30:10
01:00:50

The total should be 1 hour and 41 minutes Here is my code:

$log_in = new DateTime($log->log_in);
$log_out = new DateTime($log->log_out);
$diff = $log_out->diff($log_in);
$total += strtotime($diff->format('%H:%i:%s'));
echo $diff->format('%H:%i:%s');

1 Answers1

0

Convert the time into timestamp using strtotime() function. Then manipulate the time according your need and get result in terms of seconds.

Once you get seconds. For Hour

   $hour  = $diff % 3600

For Minute

    $Minute = ($diff - ( $hour *3600))%60;
sandeepsure
  • 1,113
  • 1
  • 10
  • 17