3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $timetocomp = "2015-10-13 08:50:17"; $dateTimeToCompare = DateTime::createFromFormat('Y-m-d H:i:s', $timetocomp); var_dump($dateTimeToCompare); $dateTimeNoW = "2015-10-13 07:48:17"; $dateTimeCompare = DateTime::createFromFormat('Y-m-d H:i:s', $dateTimeNoW); $diff = $dateTimeToCompare->diff($dateTimeCompare); var_dump($diff); echo $diff->invert; if($diff->h >= 1) { echo "difference of at least 1 hour ".$diff->h; } else { echo "difference less than 1 hour ".$diff->h; }
based on UFHW9
Output for 7.1.0 - 7.2.0
object(DateTime)#1 (3) { ["date"]=> string(26) "2015-10-13 08:50:17.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(1) ["i"]=> int(2) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 1difference of at least 1 hour 1
Output for 5.4.30 - 5.4.45, 5.5.14 - 7.0.20
object(DateTime)#1 (3) { ["date"]=> string(26) "2015-10-13 08:50:17.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(1) ["i"]=> int(2) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 1difference of at least 1 hour 1
Output for 5.4.17 - 5.4.29, 5.5.0 - 5.5.13
object(DateTime)#1 (3) { ["date"]=> string(19) "2015-10-13 08:50:17" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateInterval)#3 (15) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(1) ["i"]=> int(2) ["s"]=> int(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 1difference of at least 1 hour 1
Output for 5.4.0 - 5.4.16
object(DateTime)#1 (3) { ["date"]=> string(19) "2015-10-13 08:50:17" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateInterval)#3 (8) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(1) ["i"]=> int(2) ["s"]=> int(0) ["invert"]=> int(1) ["days"]=> int(0) } 1difference of at least 1 hour 1