How to make timeintervals per half hour?

Discussion in 'PHP' started by 123GoToAndPlay, Jul 22, 2009.

  1. #1
    Hi,


    How can i make this dyn. with php??
    
    <select name="mydropdown">
    <option value="07.00-07.30">07.00-07.30</option>
    <option value="07.30-08.00">07.30-08.00</option>
    <option value="08.00-08.30">08.00-08.30</option>
    etc.
    </select>
    
    Code (markup):
    Any suggestions??
     
    123GoToAndPlay, Jul 22, 2009 IP
  2. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ah, found this php function which does the trick
    
    function create_time_range($start, $end, $by='30 mins') {
    	/**
    	 * create_time_range 
    	 * 
    	 * @param mixed $start start time, e.g., 9:30am or 9:30
    	 * @param mixed $end   end time, e.g., 5:30 or 17:30
    	 * @param string $by   1 hour, 1 mins, 1 secs, etc.
    	 * @access public
    	 * @return void
    	 */
        $start_time = strtotime($start);
        $end_time   = strtotime($end);
    
        $times = array();
        for ( ;$start_time < $end_time; ) {
            $times[] = $start_time;
            $start_time = strtotime('+'.$by, $start_time);
        }
        $times[] = $start_time;
        return $times;
    }
    
    PHP:
     
    123GoToAndPlay, Jul 22, 2009 IP