php - How is the best way to check iteration between two hours? -
php - How is the best way to check iteration between two hours? -
i check how iteration between 2 dates interval 30 minutes.
i have example:
$one = new datetime('2012-01-20 06:00'); $two = new datetime('2012-01-20 17:30'); $first = $one->format('h:i'); $second = $two->format('h:i'); $interval = 30;
in illustration $iteration = 23, how can calculate this?
you split amount of minutes between datetimes desired interval.
$one = strtotime('2012-01-20 06:00'); $two = strtotime('2012-01-20 17:30'); $interval = 30; echo round(($two - $one) / ($interval * 60));
(i've taken shortcut , divided amount of seconds amount of seconds in 30 minutes)
http://codepad.org/yhv0hdwl
php datetime
Comments
Post a Comment