If I have a start date (say 2009-02-01
) and an end date (say 2010-01-01
), how can I create a loop to go through all the dates (months) in the range
I like the simplicity of the accepted answer, but as 3s2ng, it doesn't always work. So I tweeked it like this:
$start = strtotime('2009-02-01');
$startmoyr = date('Y', $start) . date('m', $start);
$end = strtotime('2013-12-01');
$endmoyr = date('Y', $end) . date('m', $end);
while ($startmoyr <= $endmoyr) {
echo date("F Y", $start) . "
";
$start = strtotime("+1month", $start);
$startmoyr = date('Y', $start) . date('m', $start);
}