Re: Time Loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2008-09-29 at 17:01 -0400, MDB wrote:
> Hello All, I am trying to figure out how to loop through 2 given times.  I 
> have a start time and a end time and want to look through every X mins and 
> add a radio button.  Below is my latest try, can someone please help me out?
> 
> 
>       $endTime = "17:00:00";
>       $currentTime="09:00:00";
> 
>       $num_intervals = floor(($endTime - $currentTime) / 30);

You should convert your times to minutes so you can use minute
intervals... the following was written directly into the email and so it
is UNTESTED:

<?php

    $bits = explode( ':', $currentTime );
    $currentTime = $bits[0] * 60 + $bits[1];

    $bits = explode( ':', $endTime );
    $endTime = $bits[0] * 60 + $bits[1];

    $interval = 15; // minutes
    for( $i = $currentTime; $i <= $endTime; $i += $interval )
    {
        $time = floor( $i / 60 ).':'.($i % 60).':00';
    }

?>

Adapt to fit your needs.

Note: I used a time interval like you state in your above description (X
mins). But the code you submitted used appeared to use number of time
slices instead.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux