I currently have a list of time diffs in G:i format.
I would like to add them all up but when i try to it resets at 24 back to 0.
How can i get a result like: 54:45 for example?
Thanks in advance.
date_default_timezone_set('UTC');
$username = $row['username'];
$begintime = $row['begintime'];
$endtime = $row['endtime'];
$begintime = new DateTime($begintime);
$begintime = $begintime->format('H:i');
$endtime = new DateTime($endtime);
$endtime = $endtime->format('H:i');
$difference = strtotime($endtime) - strtotime($begintime);
$difference = date('G:i', $total);
$total_hours += $difference;
Don’t use
date()to format absolute times. Since$differencecontains the time difference in seconds, it’s just a matter of simple arithmetics: