Jump to content

Select List Times


Maltby

Recommended Posts

I'm trying to create an options drop down every 15 minutes between two times.

For example if $startTime = 15:00 and $finishTime = 16:00 I want the drop down to output 15:00, 15:15, 15:30, 15:45 and 16:00.

 

Is this possible at all or am I barking up the wrong tree?

 

This is the current code I have:

$startTime = date('H:i', strtotime($appsCheck->jobIntStTime));
$finishTime = date('H:i', strtotime($appsCheck->jobIntFiTime));

do {
	$startTime += date('H:i', strtotime('+15 minutes', $startTime));
	$times .= "\t\t<option value=\"$startTime\">$startTime</option>\n";
} while ($startTime <= $finishTime);

 

I get output 16 and 17 and I get an error:

"Notice: A non well formed numeric value encountered in /home/matt/public_html/costa/applications.php on line 33"

 

 

Link to comment
https://forums.phpfreaks.com/topic/275573-select-list-times/
Share on other sites

You can do it with a simple for loop, actually.

$start = strtotime($appsCheck->jobIntStTime);
$end = strtotime($appsCheck->jobIntFiTime);
for ($time = $start; $time $hhmm = date('H:i', $time);
$times .= "\t\t\n";
}
Consider whether it's possible that the end time won't be a multiple of 15 minutes after the start time, and if so whether that matters.
Link to comment
https://forums.phpfreaks.com/topic/275573-select-list-times/#findComment-1418274
Share on other sites

Next time I'll check that "1 reply added" message.

$startTime = strtotime($appsCheck->jobIntStTime);
$finishTime = strtotime($appsCheck->jobIntFiTime);
 
for($i = $startTime; $i <= $finishTime; $i+=900) {
  $date = date('H:i', $i);
 $times .= "\t\t<option value=\"{$date}\">{$date}</option>\n";
}
Link to comment
https://forums.phpfreaks.com/topic/275573-select-list-times/#findComment-1418275
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.