0
I am using the following script to dynamically generate hours between a Start Value and a End Value with a time interval.
For example: From 8:00 am to 3:30 pm, with a 15-minute break between times.
Code:
<?php
$start = '08:00';
$end = '15:30';
$st = explode(':', $start);
$ed = explode(':', $end);
for($hour = $st[0]; $hour <= $ed[0]; $hour++)
{
for($min = $st[1]; $min < 60; $min += 15)
{
if($ed[1] >= $min and $hour <= $ed[0])
echo "Hour: {$hour}:{$min}<br/>";
}
}
But if I put 15:00 as the final value, the code does not generate me the hours with minutes, only the full hours. I need it to generate minutes even when it is a full hour set to Final Value, for example 3:00 pm.
NOTE: The script needs to be with is similar to the example, any other solution that follows a different structure can not use in my final code.
In fact it generates from 15 to 15 only until the placed... if for 30 only until 30... if for 15 only until 15... if by 45 goes until 45... This is correct ?
– rbz
So the logic is this. If I put 15 it has to generate - 8:00 - 8:15 - 8:30 and so on. The problem is that if I put a final time 15:00 instead of 15:30 as it is in the example, it does not generate me the times with minutes. Only hours 08:00 - 09:00 and so on until the final hour.
– João Victor
Always have to be :15, :30, :45 ?
– rbz
That one reply resolve? in case your interval will be
PT15M
– rray
@RBZ Yes always have to have, if I set a final time without the minutes, in case a full time 15:00 or 14:00 the script does not work properly.
– João Victor