Skip to content

Instantly share code, notes, and snippets.

@caionorder
Created August 6, 2020 22:19
Show Gist options
  • Save caionorder/6d39d6834875929009a73a765aa32e2a to your computer and use it in GitHub Desktop.
Save caionorder/6d39d6834875929009a73a765aa32e2a to your computer and use it in GitHub Desktop.
<?php
function somar_horas($time1, $time2) {
$times = array($time1, $time2);
$seconds = 0;
foreach ($times as $time)
{
list($hour,$minute,$second) = explode(':', $time);
$seconds += $hour*3600;
$seconds += $minute*60;
$seconds += $second;
}
$hours = floor($seconds/3600);
$seconds -= $hours*3600;
$minutes = floor($seconds/60);
$seconds -= $minutes*60;
if($seconds < 9)
{
$seconds = "0".$seconds;
}
if($minutes < 9)
{
$minutes = "0".$minutes;
}
if($hours < 9)
{
$hours = "0".$hours;
}
$saida = "{$hours}:{$minutes}:{$seconds}";
return $saida;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment