i am developing a booking system for clients. i'm stuck at one place. The timeslots for the given date is generated dynamically by giving, start time, end time, duration and break time.
$start = new DateTime($stTime);
$end = new DateTime($enTime);
$interval = new DateInterval("PT" . $duration. "M");
$breakInterval = new DateInterval("PT" . $break. "M");
for ($intStart = $start;
$intStart < $end;
$intStart->add($interval)->add($breakInterval)) {
$endPeriod = clone $intStart;
$endPeriod->add($interval);
if ($endPeriod > $end) {
$endPeriod=$end;
}
$starttime = $intStart->format('h:iA');
$endtime = $endPeriod->format('h:iA');
$timeslot = $starttime.' - '.$endtime;
}
Now its working successfully generating timeslots like this where duration and breaktime both are 15 mins:
09:00AM - 09:15AM
09:30AM - 09:45AM
10:00AM - 10:15AM
10:30AM - 10:45AM
11:00AM - 11:15AM
11:30AM - 11:45AM
12:00PM - 12:15PM
When some one made a booking the date, starttime and endtime will get saved in database. and i can check that there is already a booking by using this query:
select * from bookings where starttime='$start' AND endtime='$end' AND bookingdate='$date'
Now the problem is the duration is dynamic. When i change duration to 30 mins.
The new timeslots will be generated like this
09:00AM - 09:30AM
09:45AM - 10:15AM
10:30AM - 11:00AM
11:15AM - 11:45AM
12:00PM - 12:30PM
Now if want to check if the slot is already booked, the time slots are different and start and end times are different now from the ones saved in database. How can i tackle this situation? I want Old bookings with 15 mins duration to display Booked even with new Duration of 30 mins.
UPDATE
Desired Result.
when we have a booking of 10:00am to 10:30am before with 30 mins duration Desired results for 15 mins duration.
09:00AM - 09:15AM
09:30AM - 09:45AM
10:00AM - 10:30AM -- BOOKED
10:30AM - 10:45AM
11:00AM - 11:15AM
11:30AM - 11:45AM
12:00PM - 12:15PM