3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $date = new DateTime(); //$startDate = new DateTime("2017/6/24"); //$startDate->add(new DateInterval('P12M')); $startDate = new DateTime("2017/6/24"); $diff = $startDate->diff($date, true); var_dump($diff); $surplus = $diff->d > 0 ? 0 : 1; echo ($diff->y * 12 + $diff->m + $surplus); //echo $date->format('Y-m-d H:i:s'); //echo $startDate->format('Y-m-d H:i:s'); ?>
based on Rq9KF
Output for 7.3.0rc3
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.017318) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.3.0beta1
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.001991) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.3.0alpha1
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.00299) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.2.11
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.002852) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.2.6
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.003885) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.20
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.004157) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.10
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.01263) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.9
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.015709) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.8
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.004677) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.7
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.008652) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.6
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.017529) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.5
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.017831) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.4
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.016295) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.3
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.2
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.017177) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.1
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.010265) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 7.1.0
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["f"]=> float(0.004875) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.0.24
object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(1) ["h"]=> int(8) ["i"]=> int(24) ["s"]=> int(58) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(123) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 4
Output for hhvm-3.18.5 - 3.22.0
object(DateInterval)#3 (0) { } 4