Solarpitch Posted January 25, 2008 Share Posted January 25, 2008 Hi Guys, just wondering whats the best way of even how you would do this. I have two select boxes where a user chooses a start time and a finish time. If the user selects... START: 6:00 am FINISH: 10:00 am ... I want to display a list of 15 min intervals between the two times eg: 6:00 am, 6:15 am, 6:30 am, 6:45 am, 7:00 am, 7:15 am... right up until 10:00 am I take it you would use a loop but I am not sure how. Thanks Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted January 25, 2008 Share Posted January 25, 2008 <?PHP $start="6:00"; $finish="10:00"; $a=explode(":",$start); $start_hr=$a[0]; $a=explode(":",$finish); $finish_hr=$a[0]; for($i=$start_hr;$i<=$finish_hr;$i++){ echo $i.":00"."<BR>" ; echo $i.":15"."<BR>"; echo $i.":30"."<BR>"; echo $i.":45"."<BR>"; } ?> Quote Link to comment Share on other sites More sharing options...
dg Posted January 25, 2008 Share Posted January 25, 2008 <?PHP $start="6:00"; $finish="10:00"; $a=explode(":",$start); $start_hr=$a[0]; $a=explode(":",$finish); $finish_hr=$a[0]; $int_interval=15; $interval=00; for($i=$start_hr;$i<=$finish_hr;$i++) { if ($interval > 45) $interval=00; echo $i.":".$interval."<BR>" ; $interval += $int_interval; } ?> Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted January 25, 2008 Author Share Posted January 25, 2008 Many Thanks Guys, Both your solutions work fine! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 25, 2008 Share Posted January 25, 2008 I realize you marked this "Solved", but here's one more solution that uses the strtotime() and date() functions: <?php $st = strtotime(date('Y-m-d') . '6:00 am'); $en = strtotime(date('Y-m-d') . '10:00 am'); $int = 15 * 60; // number of seconds in 15 minutes for ($i = $st; $i <= $en; $i += $int) echo date('G:i a',$i) . "<br>\n"; ?> Ken Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted January 25, 2008 Author Share Posted January 25, 2008 Thanks Ken! Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted January 25, 2008 Author Share Posted January 25, 2008 Actually Ken.. your method worked the best! The only prob is it displays the time in 24 hours display.. is there anyway of changing this to a 12 hour display? ie: 15:00 --> 3:00 Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted January 25, 2008 Author Share Posted January 25, 2008 Its cool.. I had a look at the manual! just use "h" instead of "G" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.