Skip to content

Instantly share code, notes, and snippets.

@kfriend
Created February 27, 2013 04:19
Show Gist options
  • Save kfriend/5045040 to your computer and use it in GitHub Desktop.
Save kfriend/5045040 to your computer and use it in GitHub Desktop.
12 hour select field
<?php
function select_12_hour()
{
$return = '';
for ($i = 0; $i < 24; $i++)
{
$period = ($i < 12) ? 'a.m.' : 'p.m.';
$k = $i;
if ($i === 0)
{
$k = '12';
}
if ($i > 12)
{
$k = $i - 12;
}
$j = str_pad($i, 2, '0', STR_PAD_LEFT);
$return .= "<option value=\"{$j}:00:00\">{$k}:00 {$period}</option>" .
"<option value=\"{$j}:15:00\">{$k}:15 {$period}</option>" .
"<option value=\"{$j}:30:00\">{$k}:30 {$period}</option>" .
"<option value=\"{$j}:45:00\">{$k}:45 {$period}</option>";
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment