I'm trying to get all the time slots in a day with specified time interval (time interval is 2 hours i'e 120 minutes) like this
<?php
$start=strtotime('08:00');
$end=strtotime('18:00');
for ($i=$start + $k; $i<=$end - 1; $i = $i + 120*60) {
echo date('g:i A',$i) . " - " . date('g:i A',$i + 120*60 ) . '<br>';
}
?>
The above code outputs
8:00 AM - 10:00 AM
10:00 AM - 12:00 PM
12:00 PM - 2:00 PM
2:00 PM - 4:00 PM
4:00 PM - 6:00 PM
I'm trying to get the output something like below
8:00 AM - 10:00 AM
9:00 AM - 11:00 PM
10:00 AM - 12:00 PM
11:00 AM - 01:00 PM
12:00 PM - 02:00 PM
01:00 PM - 03:00 PM
02:00 PM - 04:00 PM
03:00 PM - 05:00 PM
04:00 PM - 06:00 PM
The time should not exceed 6 PM, I'm pretty new to PHP, can someone please help me on this, thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…