note 99414 deleted from function.date by danbrown
| From: | danbrown@php.net | Date: | Tue, 17 Aug 2010 16:35:57 +0000 |
| Subject: | note 99414 deleted from function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171775@lists.php.net to get a copy of this message | ||
Note Submitter: mtroy dot student at gmail dot com
----
function list_months_betweenDates($start_date, $end_date, $format = "m-Y")
{
// convertion, accept all input formats
$start_date = array("month" => date("m", strtotime($start_date)),
"year" => date("y", strtotime($start_date)));
$start_calc = (intval($start_date["year"]) * 12 ) +
intval($start_date["month"]);
$end_date = array("month" => date("m", strtotime($end_date)),
"year" => date("y", strtotime($end_date)));
$end_calc = (intval($end_date["year"]) * 12) +
intval($end_date["month"]);
// number of months
$count_month = abs($end_calc - $start_calc) + 1;
$result = array();
$month = $start_date["month"];
$year = $start_date["year"];
while($count_month > 0)
{
array_push($result, date( $format, mktime( 0, 0, 0, $month++, 1,
(($month==12)?$year++:$year) )));
$count_month--;
}
return $result;
}
// Exemple :
list_months_betweenDates('01-05-2009', '01-08-2010', 'm/Y'));
array(16) {
[0]=>
string(7) "05/2009"
[1]=>
string(7) "06/2009"
[2]=>
string(7) "07/2009"
[3]=>
string(7) "08/2009"
[4]=>
string(7) "09/2009"
[5]=>
string(7) "10/2009"
[6]=>
string(7) "11/2009"
[7]=>
string(7) "12/2010"
[8]=>
string(7) "01/2011"
[9]=>
string(7) "02/2011"
[10]=>
string(7) "03/2011"
[11]=>
string(7) "04/2011"
[12]=>
string(7) "05/2011"
[13]=>
string(7) "06/2011"
[14]=>
string(7) "07/2011"
[15]=>
string(7) "08/2011"
}