views:

862

answers:

1

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?

Thanks!!

+7  A: 

Try

$start = $month = strtotime('2009-02-01');
$end = strtotime('2011-01-01');
while($month < $end)
{
     echo date('F Y', $month), PHP_EOL;
     $month = strtotime("+1 month", $month);
}

As of PHP5.3 you can use http://www.php.net/manual/en/class.dateperiod.php

Gordon