Jump to content

Select List Times


Maltby
Go to solution Solved by requinix,

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
Share on other sites

  • Solution

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. Edited by requinix
Link to comment
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";
}
Edited by jcbones
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.