2

2 つの日付があり、Codeigniter を使用して配列内のこれら 2 つの日付の間にあるすべての日付が必要です。助けてくれてありがとう

  $fromDate =$this->input->post('fromDate');
  $toDate = $this->input->post('toDate');
  $allDate = array('all the dates between these two date');
4

2 に答える 2

3

あなたはこのようにすることができます........

        $start_date = date('Y-m-d', strtotime($start_date));
        $end_date =  date('Y-m-d', strtotime($end_date));
        $day = 86400; // Day in seconds  
        $format = 'Y-m-d'; // Output format (see PHP date funciton)  
        $sTime = strtotime($start_date); // Start as time  
        $eTime = strtotime($end_date); // End as time  
        $numDays = round(($eTime - $sTime) / $day) + 1;  
        $days = array();  
        for ($d = 0; $d < $numDays; $d++) {  
            $days[] = date($format, ($sTime + ($d * $day)));  
        }
于 2013-04-25T06:30:05.397 に答える
0

Venkat solution doesn't work for period that includes DST change from summer to winter time (-1 hour). Eg. for a given period from 2013-10-01 to 2013-10-31 a date of 2013-10-27 is added twice. One solution is to add one hour or 3600 seconds. So the statement in for loop is:

$days[] = date($format, ($sTime + ($d * $day)+ 3600));

于 2013-11-12T08:52:54.283 に答える