Hooker Posted July 13, 2012 Share Posted July 13, 2012 Hello, I'm having a little trouble deciding how to go about splitting an amount of time into intervals, i wan't to be able to set in a start and end time and split them down into 2 hour chunks so: Start: 14:00 End: 24:00 Intervals: 14:00 - 16:00, 16:00 - 18:00, 18:00 - 20:00, 20:00 - 22:00, 22:00 - 24:00 ready to be logged into a mysql database. Can anyone set me in the right direction? Thanks! Link to comment https://forums.phpfreaks.com/topic/265643-split-time-into-intervals/ Share on other sites More sharing options...
requinix Posted July 13, 2012 Share Posted July 13, 2012 start hour = 14, end hour = 24, interval hours = 2 interval start hour = start hour while start hour interval end hour = min(interval start hour + interval hours, end hour) // assuming the same day interval = [interval start hour : minute, interval end hour : minute] save interval interval start hour = interval end hour loop Or a for loop. Link to comment https://forums.phpfreaks.com/topic/265643-split-time-into-intervals/#findComment-1361421 Share on other sites More sharing options...
Hooker Posted July 13, 2012 Author Share Posted July 13, 2012 <?php $firstTime=strtotime("2012-07-13 14:00:00"); $lastTime=strtotime("2012-07-13 20:00:00"); $time=$firstTime; while ($time < $lastTime) { echo date('H:i:s', $time) . " - "; $time = strtotime('+2 hours', $time); echo date('H:i:s', $time) . "<br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/265643-split-time-into-intervals/#findComment-1361431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.