Time of Day Incremented every 30 Minutes Array


/ Published in: PHP
Save to your folder(s)

These arrays are good for filling out a drop down menu for time that increments by 30 minutes. The forms can submit the data and be useful for inserting it into a database for time of day information.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. $hour_slot = 0;
  4. $min_slot = 0;
  5.  
  6. for( $i = 0; $i<47; $i++)
  7. {
  8. if( $i == 0)
  9. {
  10. $str_time = date('g:i A', strtotime($hour_slot.':'.$min_slot) );
  11. $arr_time[$str_time] = $str_time;
  12. }
  13.  
  14. if( $i%2 == 0 )
  15. {
  16. $min_slot=30;
  17. }
  18. else
  19. {
  20. $min_slot=0;
  21. }
  22.  
  23. $str_time = date('g:i A', strtotime($hour_slot.':'.$min_slot) );
  24. $arr_time[$str_time] = $str_time;
  25.  
  26. if( $i%2 == 0 )
  27. {
  28. $hour_slot++;
  29. }
  30. }
  31.  
  32. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.