SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looping through times but with breaks

    Hi guys

    I know how to do a standard loop of 30 minutes from a start time to a end time but I want to loop through times every 30 minutes from 9am to 5pm but with 15 minute breaks at 10:30 and 14:45

    This will then start the 30 minute loop again from after the 15 minute break. So it should display like this

    09:00
    09:30
    10:00 then 15 minute break
    10:45
    11:15
    11:45
    12:15
    12:45
    13:15
    13:45
    14:15 then 15 minute break
    15:00
    15:30
    16:00
    16:30

    Any help on how to do this would be greatly appreciated

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    if(time == 10:00 || time == 14:15) { time += 00:15 }

    looping variables arnt immutable.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Here is my example:
    PHP Code:
    <?
       $event_length 
    30;
       
    $etime strtotime("09:00:00");
       while(
    1)
       {
           
    $next_time date('H:i'$etime);
           if(
    $next_time=="10:30" || $next_time=="14:45")
           {
               
    $etime strtotime("+15 minutes"$etime);
               
    $next_time date('H:i'$etime);
               echo 
    " -- 15 minute break";
           }
           else
           {
               echo 
    "<br>$next_time";
               
    $etime strtotime("+$event_length minutes"$etime);
           }
           if(
    $next_time=="16:30") break;
       }
    ?>
    You can test it out here:
    http://w-cms.org/test/looptime.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •