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
https://forums.phpfreaks.com/topic/211488-php-booking-times/
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
https://forums.phpfreaks.com/topic/211488-php-booking-times/#findComment-1102678
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.