CMcP_CMT Posted October 13, 2012 Share Posted October 13, 2012 Hello, I'm having a little trouble figuring out how to split an amount of time into intervals with a break time in between each segment. I wan't to be able to set a start and end time and split them down into 30 minute chunks with 30 minute breaks in between: Start: 11:00 End: 19:00 Intervals: 11:00 - 11:30, 12:00 - 12:30, 13:00 - 13:30 ... etc. Any help that's given will be greatly appreciated! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/269435-php-time-intervals/ Share on other sites More sharing options...
Barand Posted October 13, 2012 Share Posted October 13, 2012 try <?php $start = mktime(11,0,0); $end = mktime(19,0,0); for ($h = $start; $h <= $end; $h += 3600) { printf ('%s - %s<br />', date('H:i', $h), date('H:i', $h + 1800)); } ?> Results: 11:00 - 11:30 12:00 - 12:30 13:00 - 13:30 14:00 - 14:30 15:00 - 15:30 16:00 - 16:30 17:00 - 17:30 18:00 - 18:30 19:00 - 19:30 Quote Link to comment https://forums.phpfreaks.com/topic/269435-php-time-intervals/#findComment-1385032 Share on other sites More sharing options...
CMcP_CMT Posted October 18, 2012 Author Share Posted October 18, 2012 This is exactly what I needed! Thanks for all of your help! Quote Link to comment https://forums.phpfreaks.com/topic/269435-php-time-intervals/#findComment-1385929 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.