Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/269435-php-time-intervals/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/269435-php-time-intervals/#findComment-1385032
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.