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 08:49: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 k9iDN
Output for 7.1.0 - 7.2.0
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(1) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 1difference less than 1 hour 0
Output for 5.3.27 - 5.3.29, 5.4.17 - 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(1) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 1difference less than 1 hour 0
Output for 5.3.18 - 5.3.26, 5.4.1 - 5.4.16
object(DateInterval)#3 (8) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(1) ["s"]=> int(0) ["invert"]=> int(1) ["days"]=> int(0) } 1difference less than 1 hour 0