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" Quote Link to comment https://forums.phpfreaks.com/topic/275573-select-list-times/ Share on other sites More sharing options...
Solution requinix Posted March 12, 2013 Solution Share Posted March 12, 2013 (edited) 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. Edited March 12, 2013 by requinix Quote 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 (edited) 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 March 12, 2013 by jcbones Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/275573-select-list-times/#findComment-1418339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.