Posted By

donkeykong on 05/27/13


Tagged

time DateTime am pm


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

IMPGTX


Time of Day Incremented every 30 Minutes Array


 / Published in: PHP
 

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.

  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  

You need to login to post a comment.