3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $currentDate = new DateTime(); $targetDate = new DateTime('2015-03-05 11:11:11'); $interval = $currentDate->diff($targetDate); var_dump($interval); // Uncomment and isset will give the expected response var_dump($interval->y); var_dump($interval->m); var_dump(isset($interval->y)); var_dump(isset($interval->m));
based on D7bcM
Output for 7.2.0
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.002901) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.10
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.201671) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.8
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.018197) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.7
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.010481) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.6
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.02465) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.5
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.043071) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.4
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.038655) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.3
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.2
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.072921) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.1
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.010697) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 7.1.0
object(DateInterval)#3 (16) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["f"]=> float(0.012368) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for 5.4.17 - 5.6.30, 7.0.0 - 7.0.20
object(DateInterval)#3 (15) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(886) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } int(2) int(5) bool(true) bool(true)
Output for hhvm-3.10.1 - 3.17.3
object(DateInterval)#3 (0) { } int(2) int(5) bool(false) bool(false)
Output for 5.4.0 - 5.4.1, 5.4.3 - 5.4.16
object(DateInterval)#3 (8) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(31) ["invert"]=> int(1) ["days"]=> int(886) } int(2) int(5) bool(true) bool(true)
Output for 5.4.2
object(DateInterval)#3 (8) { ["y"]=> int(2) ["m"]=> int(5) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(28) ["s"]=> int(30) ["invert"]=> int(1) ["days"]=> int(886) } int(2) int(5) bool(true) bool(true)