note 52198 deleted from function.strtotime by betz
| From: | betz@php.net | Date: | Sun, 24 Apr 2005 07:33:21 +0000 |
| Subject: | note 52198 deleted from function.strtotime by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-88476@lists.php.net to get a copy of this message | ||
Note Submitter: websafe at partybitchez dot org
Reason: bad code
----
<?php
function count_months($start_date, $end_date) {
# Returns whole-month-count between two dates
# websafe<at>partybitchez<dot>org
# usage
# count_months("1978-02-18", "2028-08-12");
#
$start_date_unixtimestamp = strtotime($start_date);
$end_date_unixtimestamp = strtotime($end_date);
$calculated_date_unixtimestamp = $start_date_unixtimestamp;
$counter=0;
while ($calculated_date_unixtimestamp < $end_date_unixtimestamp)
{
$counter++;
$calculated_date_unixtimestamp = strtotime($start_date . " +{$counter} months");
}
return $counter;
}
?>
<?php
echo 'The result of count_months("1996-02-18", "2005-11-24") is ' .
count_months("1996-02-18", "2005-11-24") . "<br />";
echo 'The result of count_months("2005-04-24", "2005-04-24") is ' .
count_months("2005-04-24", "2005-04-24") . "<br />";
echo 'The result of count_months("2005-04-24", "2005-04-25") is ' .
count_months("2005-04-24", "2005-04-25") . "<br />";
echo 'The result of count_months("1978-02-18", "2028-08-12") is ' .
count_months("1978-02-18", "2028-08-12") . "<br />";
?>