Skip to content

Instantly share code, notes, and snippets.

@visb
Last active March 30, 2023 17:34
Show Gist options
  • Save visb/ffaa76d7377a22a4b062 to your computer and use it in GitHub Desktop.
Save visb/ffaa76d7377a22a4b062 to your computer and use it in GitHub Desktop.
Somar horas com php
<?php
function sumHours($firstHour, $secondHour) {
$baseDate = date('Y-m-d');
$baseTime = strtotime($baseDate . ' 00:00:00');
$firstTime = strtotime($baseDate . ' ' . $firstHour) - $baseTime;
$secondTime = strtotime($baseDate . ' ' . $secondHour) - $baseTime;
$resultTime = $firstTime + $secondTime;
return date('H:i:s', $baseTime + $resultTime);
}
echo sumHours('00:01:00', '00:00:50');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment