petenaylor Posted August 23, 2010 Share Posted August 23, 2010 Hi all I am trying to edit a piece of code to change possible times for a booking system. This is the code I have: $count=0; for($b=$startTime;$b<$endTime;$b++){ if($count==$tempVar2){ $availability .= "</td><td align='left' valign='top'>"; } if(in_array($b,$reservedArray)){ $availability .= $b.":00 ".($b<12?"am":"pm")." - ".($b+1).":00 ".($b+1<12?"am":"pm")." - Booked.<br>"; } else { $availability .=$b.":00 ".($b<12?"am":"pm")." - ".($b+1).":15 ".($b+1<13?"am":"pm")."- <input type=\"checkbox\" value=\"".$b."\" name=\"time[]\" ><br>"; } $count++; } It gives me the following times: 09:00 am - 10:15 am 10:00 am - 11:15 am 11:00 am - 12:15 am 12:00 pm - 13:15 pm 13:00 pm - 14:15 pm 14:00 pm - 15:15 pm 15:00 pm - 16:15 pm 16:00 pm - 17:15 pm How can I change it so I can have the following times available: 10:00 am - 10:30 am 10:45 am - 11:15 am 11:30 am - 12:00 pm 12:15 pm - 12:30 pm etc... Many thanks for you help Pete. Quote Link to comment Share on other sites More sharing options...
joel24 Posted August 23, 2010 Share Posted August 23, 2010 I would steer clear of your current code, looks like quite a convoluted solution. It isn't a complex problem, re-write that block of code with time stored as unix timecodes and strtotime. Much easier to use unix timecodes when dealing with times, then you can have something along the lines of echo date("g:i a", $unixTimeCode); which will echo hours:minutes AM/PM 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.