I want to create a time slot in which booking should be allowed from 10:00 AM till 07:00 PM.
Condition: each service time 60 min & 0 min break. like This,
10:00 AM - 11:00 AM
11:00 AM - 12:00 AM
12:00 AM - 13:00 AM
13:00 AM - 14:00 PM
Can you guys provide me the solutions for this problem? Thanks in advance.
Try this ...
function getServiceScheduleSlots($duration, $start,$end)
{
$start = new DateTime($start);
$end = new DateTime($end);
$start_time = $start->format('H:i');
$end_time = $end->format('H:i');
$i=0;
while(strtotime($start_time) <= strtotime($end_time)){
$start = $start_time;
$end = date('H:i',strtotime('+'.$duration.' minutes',strtotime($start_time)));
$start_time = date('H:i',strtotime('+'.$duration.' minutes',strtotime($start_time)));
$i++;
if(strtotime($start_time) <= strtotime($end_time)){
$time[$i]['start'] = $start;
$time[$i]['end'] = $end;
}
}
return $time;
}
$slopt = getServiceScheduleSlots(60, '10:00AM', '07:00PM')
Result will be like this:
Array
(
[1] => Array
(
[start] => 10:00
[end] => 11:00
)
[2] => Array
(
[start] => 11:00
[end] => 12:00
)
[3] => Array
(
[start] => 12:00
[end] => 13:00
)
[4] => Array
(
[start] => 13:00
[end] => 14:00
)
[5] => Array
(
[start] => 14:00
[end] => 15:00
)
[6] => Array
(
[start] => 15:00
[end] => 16:00
)
[7] => Array
(
[start] => 16:00
[end] => 17:00
)
[8] => Array
(
[start] => 17:00
[end] => 18:00
)
[9] => Array
(
[start] => 18:00
[end] => 19:00
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With