I would like to have a script that prints out a list of hours, starting from the current time until a defined time.
An example out put would look like this:
<button>09:00 – 10:00</button>
<button>11:00 – 12:00</button>
<button>13:00 – 14:00</button>
<button>15:00 – 16:00</button>
<button>17:00</button>
So the current time is 09:XX and the end time is 17:00.
The code I have so far is this:
[CODE]<?php
function create_time_range($start, $end, $by) {
$start_time = strtotime($start);
$end_time = strtotime($end);
$current = time();
$add_time = strtotime(‘+’.$by, $current);
$diff = $add_time-$current;
$times = array();
while ($start_time < $end_time) {
$times[] = $start_time;
$start_time += $diff;
}
$times[] = $start_time;
return $times;
}
$time_now = date(“G”).”:00″;
$last_working_hour = date(’17:00′);
$times = create_time_range($time_now, $last_working_hour, ’60 mins’);
foreach ($times as $key => $time)
echo “<button class=’times’>”.date(‘G:i’, $time) . ‘</button> ‘;
?>
This produces:
<button>12:00</button>
<button>13:00</button>
<button>14:00</button>
<button>15:00</button>
<button>16:00</button>
<button>17:00</button>
Not in the grouping I want. Also if the time is 14:XX it should not produce:
<button>13:00 – 14:00</button>
<button>15:00 – 16:00</button>
<button>17:00</button>
But rather:
<button>14:00</button>
<button>15:00 – 16:00</button>
<button>17:00</button>