timeDiffs - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of timeDiffs.php
- <?php
- function counter($time, $modify = '+1 day') {
- $date = new DateTime($time);
- $date->modify($modify);
- $diff = $date->diff(new DateTime($time));
- $h = ($diff->days > 0 ? $diff->days * 24 : 0) + $diff->h;
- $i = $diff->i;
- $s = $diff->s;
- return "$h:{$diff->i}:{$diff->s}";
- }
- function timeAdd($add, $time = "00:00:00") {
- list($h1, $i1, $s1, $h2, $i2, $s2) = explode(':', $time.":".$add);
- $s = $s1 + $s2;
- $i = $s > 59 ? intdiv($s, 60) : 0;
- $s = $s > 59 ? $s % 60 : $s;
- $i += $i1 + $i2;
- $h = $i > 59 ? intdiv($i, 60) : 0;
- $i = $i > 59 ? $i % 60 : $i;
- $h += $h1 + $h2;
- return "$h:$i:$s";
- }
- function timeAddMulti() {
- $args = func_get_args();
- $start = "00:00:00";
- for ($i = 0; $i < count($args); $i++)
- $start = timeAdd($args[$i], $start);
- return $start;
- }
- $time = "15.06.2018 13:32";
- echo timeAdd("23:59:23", "22:59:23");