Skip to content

Instantly share code, notes, and snippets.

@jotapepinheiro
Created May 4, 2018 20:36
Show Gist options
  • Save jotapepinheiro/b31766166c329878c634470633e26fac to your computer and use it in GitHub Desktop.
Save jotapepinheiro/b31766166c329878c634470633e26fac to your computer and use it in GitHub Desktop.
Somar Horas
<?php
function soma_horas() {
$i = $s = $hour = $min = $sec = 0;
foreach (func_get_args() as $time) {
sscanf($time, '%d:%d:%d', $hour, $min, $sec);
$i += ($hour * 60) + $min + ($sec / 60);
$s += $sec;
}
if ($h = floor($i / 60)) {
$i %= 60;
$s %= 60;
}
return sprintf('%02d:%02d:%02d', $h, $i, $s);
}
echo soma_horas('01:50:50', '30:10:30', '02:10:15'); #34:11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment