3v4l.org

run code in 300+ PHP versions simultaneously
<?php $date1 = new \DateTime('2006-04-12T12:30:00'); $date2 = new \DateTime('2006-04-14T11:30:00'); //determine what interval should be used - can change to weeks, months, etc $interval = new \DateInterval('PT1H'); //create periods every hour between the two dates $periods = new \DatePeriod($date1, $interval, $date2); //count the number of objects within the periods $hours = iterator_count($periods); echo $hours . ' hours';

preferences:
58.17 ms | 402 KiB | 5 Q