note 22540 added to function.date
| From: | dan@php.net | Date: | Fri, 21 Jun 2002 11:05:23 +0000 |
| Subject: | note 22540 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-32090@lists.php.net to get a copy of this message | ||
Here is month diff just like mysql does...it is called period_diff
/**
* Function will determine number of months between two dates
*
* This is the same implementation as the mysql function PERIOD_DIFF and
* will work with the awkward month period to determine the number
* of months between two dates.
*
* @param int initial timestamp
* @param int final timestamp
*
* @access public
* @return int months difference between two dates
*/
function period_diff($in_dateLow, $in_dateHigh) {
// swap dates if they are backwards
if ($in_dateLow > $in_dateHigh) {
$tmp = $in_dateLow;
$in_dateLow = $in_dateHigh;
$in_dateHigh = $tmp;
}
$dateLow = $in_dateLow;
$dateHigh = strftime('%m/%Y', $in_dateHigh);
$periodDiff = 0;
while (strftime('%m/%Y', $dateLow) != $dateHigh) {
$periodDiff++;
$dateLow = strtotime('+1 month', $dateLow);
}
return $periodDiff;
}
--
http://www.php.net/manual/en/function.date.php
http://master.php.net/manage/user-notes.php?action=edit+22540
http://master.php.net/manage/user-notes.php?action=delete+22540
http://master.php.net/manage/user-notes.php?action=reject+22540