Forum Moderators: coopster
<?php
$qty = 10;// How many to generate
// Use this line to start at an arbitrary time:
$st = strtotime('12:00pm',time());
// Uncomment this line to start at current time:
// $st = time();
$mins = date('i',$st);
$hrs = date('G',$st);
// These next lines roll an odd time to the next half-hour interval.
// If you start at an arbitrary time, you can comment/delete
// From here - - - - -
if($mins > 30) {
$mins = 0;
$hrs++;
}
elseif($mins > 0)
$mins = 30;
$st = strtotime("$hrs:$mins",time());
// - - - to here
for($i = 0; $i < $qty; $i++) {
echo '<option value="' . sprintf('%02d%02d',$hrs,$mins) . '">' . date('g:i a',$st) . "</option>\n";
$st += 1800;// 30 minutes
$hrs = date('G',$st);
$mins = date('i',$st);
}// EndFor
?>
$t = strtotime("Midnight"); // set this to your start point...:)
echo "<select name=\"whatever\">\n";
for($i=0; $i<48; $i++)
{
echo "\t<option value=\"" . strftime("%I:%M%p", $t) . "\">" . strftime("%I:%M%p", $t) . "</option>\n";
$t += (30 * 60);
}
echo "</select>";