note 99414 added to function.date
| From: | mtroy dot student at gmail dot com | Date: | Mon, 16 Aug 2010 11:03:33 +0000 |
| Subject: | note 99414 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171728@lists.php.net to get a copy of this message | ||
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"
}
----
Server IP: 69.147.83.197
Probable Submitter: 84.37.8.242
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/99414
Del: integrated -- https://master.php.net/note/delete/99414/integrated
Del: useless -- https://master.php.net/note/delete/99414/useless
Del: bad code -- https://master.php.net/note/delete/99414/bad+code
Del: spam -- https://master.php.net/note/delete/99414/spam
Del: non-english -- https://master.php.net/note/delete/99414/non-english
Del: in docs -- https://master.php.net/note/delete/99414/in+docs
Del: other reasons-- https://master.php.net/note/delete/99414
Reject -- https://master.php.net/note/reject/99414
Search -- https://master.php.net/manage/user-notes.php