Get Months From a Given Date Range

//code
function getMonthsInRange($startDate, $endDate) {
$months = array();
while (strtotime($startDate) <= strtotime($endDate)) {
    $month = date('Y', strtotime($startDate))."-".date('M', strtotime($startDate));
	array_push($months,$month);
    $startDate = date('d M Y', strtotime($startDate.'+ 1 month'));
}

return $months;
}

Leave a Reply

Your email address will not be published. Required fields are marked *