Created
May 10, 2018 16:31
-
-
Save petk/8792ddff820ce1722feb8542ab624aa6 to your computer and use it in GitHub Desktop.
PHP example of DateInterval difference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getDiff($start, $end) | |
{ | |
$start = explode(':', $start); | |
$end = explode(':', $end); | |
$start = new DateInterval('PT'.$start[0].'H'.$start[1].'M'.$start[2].'S'); | |
$end = new DateInterval('PT'.$end[0].'H'.$end[1].'M'.$end[2].'S'); | |
$startTime = new DateTime(); | |
$startTime->add($start); | |
$endTime = new DateTime(); | |
$endTime->add($end); | |
$diff = $endTime->diff($startTime); | |
return $diff->format('%H:%I:%S'); | |
} | |
var_dump(getDiff('178:10:28', '182:00:00')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment