3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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'), ])); }
based on Ic5SG
Output for 7.1.0 - 7.3.0alpha1
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(1) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "10:11:10" object(DateInterval)#4 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(15) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "10:15:10" object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(16) ["s"]=> int(34) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "10:16:34" object(DateInterval)#4 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(21) ["i"]=> int(48) ["s"]=> int(34) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "21:48:34" object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(19) ["i"]=> int(35) ["s"]=> int(49) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "19:35:49"
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.0.20
object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(1) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "10:11:10" object(DateInterval)#4 (15) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(15) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "10:15:10" object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(16) ["s"]=> int(34) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "10:16:34" object(DateInterval)#4 (15) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(21) ["i"]=> int(48) ["s"]=> int(34) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "21:48:34" object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(19) ["i"]=> int(35) ["s"]=> int(49) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(8) "19:35:49"
Output for hhvm-3.15.4
object(DateInterval)#3 (0) { } string(8) "10:11:10" object(DateInterval)#6 (0) { } string(8) "10:15:10" object(DateInterval)#9 (0) { } string(8) "10:16:34" object(DateInterval)#12 (0) { } string(8) "21:48:34" object(DateInterval)#15 (0) { } string(8) "19:35:49"