Jump to content

PHP booking times


petenaylor

Recommended Posts

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.