Maltby Posted March 12, 2013 Share Posted March 12, 2013 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 More sharing options...
requinix Posted March 12, 2013 Share Posted March 12, 2013 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$hhmm\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 More sharing options...
jcbones Posted March 12, 2013 Share Posted March 12, 2013 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 More sharing options...
Maltby Posted March 13, 2013 Author Share Posted March 13, 2013 Ah! Thanks for the help guys Link to comment https://forums.phpfreaks.com/topic/275573-select-list-times/#findComment-1418339 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.