This is my current code and below is the output of this code.But I need to do some correction on this.
$startTimeInterval = 15;
$duration = 20;
$open = '2017-09-29T10:00:00-05:00';
$close = '2017-09-29T17:30:00-05:00';
$startTimeInterval = $startTimeInterval.' minutes';
$interval = DateInterval::createFromDateString($startTimeInterval);
$begin = new DateTime($open);
$end = new DateTime($close);
$end->add($interval);
$periods = iterator_to_array(new DatePeriod($begin, $interval, $end));
$start = array_shift($periods);
$slot = array();
foreach ($periods as $time) {
$slot[]= $start->format('h:iA'). ' - '. $time->format('h:iA');
$start = $time;
}
echo '<pre>';print_r($slot);exit;
OutPut
[0] => 10:00AM - 10:15AM
[1] => 10:15AM - 10:30AM
[2] => 10:30AM - 10:45AM
[3] => 10:45AM - 11:00AM
[4] => 11:00AM - 11:15AM
........
[28] => 05:00PM - 05:15PM
[29] => 05:15PM - 05:30PM
I need this
[0] => 10:00AM - 10:20AM
[1] => 10:15AM - 10:35AM
[2] => 10:30AM - 10:50AM
[3] => 10:45AM - 11:05AM
[4] => 11:00AM - 11:20AM
........
[28] => 05:00PM - 05:20PM
[29] => 05:15PM - 05:35PM
Horizontally it will add duration and vertically it will add startTimeInterval