SHARE
TWEET

Untitled

a guest Oct 19th, 2017 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. * create_time_range
  4. *
  5. * @param mixed $start start time, e.g., 9:30am or 9:30
  6. * @param mixed $end   end time, e.g., 5:30pm or 17:30
  7. * @param string $by   1 hour, 1 mins, 1 secs, etc.
  8. * @access public
  9. * @return void
  10. */
  11. function create_time_range($start, $end, $by='30 mins') {
  12.  
  13.     $start_time = strtotime($start);
  14.     $end_time   = strtotime($end);
  15.  
  16.     $current    = time();
  17.     $add_time   = strtotime('+'.$by, $current);
  18.     $diff       = $add_time-$current;
  19.  
  20.     $times = array();
  21.     while ($start_time < $end_time) {
  22.        $times[] = $start_time;
  23.        $start_time += $diff;
  24.     }
  25.     $times[] = $start_time;
  26.     return $times;
  27. }
  28.  
  29. // create array of time ranges
  30. $times = create_time_range('9:30', '17:30', '30 mins');
  31.  
  32. foreach ($times as $key => $time) {
  33.   $times[$key] = date('H:i', $time);
  34. }
  35.  
  36. ?>
RAW Paste Data
Top