3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testCases = [ ['2017-06-30 15:00:00', '2017-06-30 15:01:00'], ['2017-06-30 15:00:00', '2017-06-30 15:15:00'], ['2017-06-30 15:00:00', '2017-06-30 15:16:34'], ['2017-06-30 15:00:00', '2017-07-01 12:48:34'], ['2017-06-30 16:18:45', '2017-07-01 11:54:34'], ]; foreach ($testCases as $test) { list($inicio, $encerramento) = $test; $inicio = DateTime::createFromFormat('Y-m-d H:i:s', $inicio); $encerramento = DateTime::createFromFormat('Y-m-d H:i:s', $encerramento); $duracao = $inicio->diff($encerramento, true); var_dump($duracao); var_dump(join(':', [ str_pad($duracao->days*24 + $duracao->h, 2, STR_PAD_RIGHT, '0'), str_pad($duracao->i, 2, STR_PAD_RIGHT, '0'), str_pad($duracao->s, 2, STR_PAD_RIGHT, '0'), ])); }
Output for git.master, git.master_jit, rfc.property-hooks
object(DateInterval)#3 (10) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(1) ["s"]=> int(0) ["f"]=> float(0) ["invert"]=> int(0) ["days"]=> int(0) ["from_string"]=> bool(false) } string(8) "10:11:10" object(DateInterval)#4 (10) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(15) ["s"]=> int(0) ["f"]=> float(0) ["invert"]=> int(0) ["days"]=> int(0) ["from_string"]=> bool(false) } string(8) "10:15:10" object(DateInterval)#3 (10) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(16) ["s"]=> int(34) ["f"]=> float(0) ["invert"]=> int(0) ["days"]=> int(0) ["from_string"]=> bool(false) } string(8) "10:16:34" object(DateInterval)#4 (10) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(21) ["i"]=> int(48) ["s"]=> int(34) ["f"]=> float(0) ["invert"]=> int(0) ["days"]=> int(0) ["from_string"]=> bool(false) } string(8) "21:48:34" object(DateInterval)#3 (10) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(19) ["i"]=> int(35) ["s"]=> int(49) ["f"]=> float(0) ["invert"]=> int(0) ["days"]=> int(0) ["from_string"]=> bool(false) } string(8) "19:35:49"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
91.67 ms | 404 KiB | 8 Q