[thelist] PHP time based for/next loop

fstorr fffrancis at fstorr.demon.co.uk
Sun Jan 18 04:55:47 CST 2004


Hi all

I think I've got to the "wood for trees" stage...

I need a dropdown split into fifteen minute options: 00, 15, 30, 45. So 
far, so easy.  But, I need my PHP page to look at the current time, work 
out what quarter it belongs to and select the correct <option>.  To save 
looping 60 times (one for each minute), I've tried to divide the minutes 
by 15 and then round the result.  It sort of works, but fails in 
situations such as when it's 54 minutes past the hour.  This works out 
as 54/15 = 3.6, which is rounded to 4 so it selects the 00 quarter. 
Likewise, 9 minutes past is 9/15 = 0.6, rounded is 1 so that selects the 
15 option.

What I want is minutes between 0 and 14 to use the 00 option, 15 to 29 
to use the 15 option, 30 to 44 to use the 30 option and 45-59 to use the 
45 option.  But, I don't want to have to loop 60 times.

Help!

Thanks

Francis



More information about the thelist mailing list