How to sum up time in php? -


this question has answer here:

how sum time in php. example have series of time duration logs:

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

the total should 1 hour , 41 minutes here 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'); 

convert time timestamp using strtotime() function. manipulate time according need , result in terms of seconds.

once seconds. hour

   $hour  = $diff % 3600 

for minute

    $minute = ($diff - ( $hour *3600))%60; 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -