Skip to content

Instantly share code, notes, and snippets.

@acodesmith
Last active August 29, 2015 14:03
Show Gist options
  • Save acodesmith/9d949aeca74997d3b9d4 to your computer and use it in GitHub Desktop.
Save acodesmith/9d949aeca74997d3b9d4 to your computer and use it in GitHub Desktop.
Select Dropdown for Hours in the day. Value is ready for string to time conversion.
<select>
<?php $first = false;
for($t = 12; $t<=23; $t++): ?>
<?php for($m = 0; $m<=45; $m+=15): ?>
<?php $m = $m == 0 ? sprintf("%02s", $m): $m; ?>
<option value="<?php echo ($t == 12 && !$first ? '00' : ($t < 10 ? '0'.$t : $t)).':'.$m.':00'; ?>">
<?php echo $t > 12 ? ($t-12 == 0 ? 12 : $t-12).':'.($m).' PM' : $t.':'.$m.' AM'; ?>
</option>
<?php endfor; ?>
<?php if($t == 12 && !$first){
$first = true;
$t = 0;
}
endfor;?>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment