This question already has an answer here:
- How can I get a range of dates in php? 3 answers
I'm preparing an appointment script for entering visiting start hours and end hours like 09:00 and 20:00 and each visit period is 45 minutes.
I want to add 45 minutes from start time to end time within a loop. But with samples on internet I couldn't do it.
Visiting times are dynamic I mean it could be 09:00-20:00 or 11:00-23:00 etc.
The exact solution I'm trying to do is:
$visit_start = '09:00';
$visit_end = '20:00';
$difference = $visit_end - $visit_start;
$i = 1;
while( $i <= $difference )
{
print $visit_hour_list = $visit_start + 45;
$i++;
}
and the print out will be like:
09:00
09:45
10:30
11:15
12:00
until to end hour. But I have no clue how that could work.
As already answered in the similar question "How can I get a range of dates in php?", you can make use of the
DatePeriod
class in PHP to iterate over each 45 minute times' between a start and end time:Demo:
Output: