I am trying to create two select lists both filled with the same times. It’s basically for the user to select a start time and end time. I’ve calculated these as my times:
$startTime = 0; //00:00
$endTime = 86100; //23:55'
$now = $startTime;
and then I’m incrementing like this:
$now += 300;
where 300 = 5 minutes, therefore I’m incrementing the time by 5 minutes during each loop.
Therefore, my select lists should look like this:
00:00
00:05
00:10
...
...
23:45
23:50
23:55
The whole thing works, apart from the actual times being printed. I am getting this:
1:00
1:05
...
...
00:45
00:50
00:55
I suspect the problem is the fact we are now in Daylight Saving Time here in the UK. How should I therefore tackle this problem?
This is my actual method:
public function timeSelectList()
{
$startTime = 0; //00:00
$endTime = 86100; //23:55'
$now = $startTime;
$startSelectList = '<label for="startSelect">Start Time</label><select name="startSelect" id="startSelect">';
$endSelectList = '<label for="endSelect">End Time</label><select name="endSelect" id="endSelect">';
while($now <= $endTime)
{
if($now == 61200)//17:00
{
$startSelectList .= '<option value="'.$now.'" selected="selected">'.date('H:i', $now).'</option>';
$endSelectList .= '<option value="'.$now.'">'.date('H:i', $now).'</option>';
}
else if($now == 64800)//18:00
{
$startSelectList .= '<option value="'.$now.'">'.date('H:i', $now).'</option>';
$endSelectList .= '<option value="'.$now.'" selected="selected">'.date('H:i', $now).'</option>';
}
else
{
$startSelectList .= '<option value="'.$now.'">'.date('H:i', $now).'</option>';
$endSelectList .= '<option value="'.$now.'">'.date('H:i', $now).'</option>';
}
$now += 300; //increment 5 minutes (300 seconds = 5 minutes
}
$startSelectList .= '</select>';
$endSelectList .= '</select>';
return $startSelectList.$endSelectList;
}
Why not just write a function that will convert seconds into hours/minutes?