You can try with these functions :
function get_date_range ($start, $end) {
$dates = array();
$start = strtotime($start .'01');
$end = strtotime($end .'01');
while ($start <= $end) {
$dates [] = array(date('Ym01', $start), date('Ymt', $start));
$start = strtotime(add_month(date('Y-m-01', $start), 1));
}
return $dates;
}
function add_month($date_value, $months, $format = 'm/d/Y') {
$date = new DateTime($date_value);
$start_day = $date->format('j');
$date->modify("+{$months} month");
$end_day = $date->format('j');
if ($start_day != $end_day)
$date->modify('last day of last month');
return $date->format($format);
}
$start = "201301";
$end = "201303";
$dates = get_date_range($start, $end);
print_r($dates);
Here the add_month function will help you to avoid problems with the date when adding one month to January 31st.
If you use strtotime it will go to March when adding 1 month to January 31st..
Output will be :
Array
(
[0] => Array
(
[0] => 2013-01-01
[1] => 2013-01-31
)
[1] => Array
(
[0] => 2013-02-01
[1] => 2013-02-28
)
[2] => Array
(
[0] => 2013-03-01
[1] => 2013-03-31
)
)
Hope this helps you :)