Jump to content

Php Time Intervals


CMcP_CMT

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.