Monday 22 February 2016

given two date get month year

/*---------------------------------------
    Get month given two date
    ---------------------------------------*/
    function get_months($date1, $date2) {
        $time1  = strtotime($date1);
        $time2  = strtotime($date2);
        $my     = date('mY', $time2);
        $months= array();
        $months[date('M-Y', $time1)] = 0;

        while($time1 < $time2) {
           $time1 = strtotime(date('Y-m-d', $time1).' +1 month');
           if(date('mY', $time1) != $my && ($time1 < $time2))
              $months[date('M-Y', $time1)] = 0;
        }

        $months[date('M-Y', $time2)] = 0;
        return $months;
    }
   

No comments:

Post a Comment