Posted By

tylerhall on 10/11/06


Tagged

time dropdown hour minute


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

hudge
vali29
dantreacy
Tate


Hour Minute Dropdown


 / Published in: PHP
 

Outputs hour, minute, am/pm dropdown boxes

  1. function hourmin($hid = "hour", $mid = "minute", $pid = "pm", $hval = "", $mval = "", $pval = "")
  2. {
  3. if(empty($hval)) $hval = date("h");
  4. if(empty($mval)) $mval = date("i");
  5. if(empty($pval)) $pval = date("a");
  6.  
  7. $hours = array(12, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11);
  8. $out = "<select name='$hid' id='$hid'>";
  9. foreach($hours as $hour)
  10. if(intval($hval) == intval($hour)) $out .= "<option value='$hour' selected>$hour</option>";
  11. else $out .= "<option value='$hour'>$hour</option>";
  12. $out .= "</select>";
  13.  
  14. $minutes = array("00", 15, 30, 45);
  15. $out .= "<select name='$mid' id='$mid'>";
  16. foreach($minutes as $minute)
  17. if(intval($mval) == intval($minute)) $out .= "<option value='$minute' selected>$minute</option>";
  18. else $out .= "<option value='$minute'>$minute</option>";
  19. $out .= "</select>";
  20.  
  21. $out .= "<select name='$pid' id='$pid'>";
  22. $out .= "<option value='am'>am</option>";
  23. if($pval == "pm") $out .= "<option value='pm' selected>pm</option>";
  24. else $out .= "<option value='pm'>pm</option>";
  25. $out .= "</select>";
  26.  
  27. return $out;
  28. }

Report this snippet  

You need to login to post a comment.