Months are a rather significant exception to date differences than
any other unit of time.  This is why mysql made a function
specifically for this purpose.  I recently had to use it and noticed
the number of users on php-general asking this question, so I wanted
to post true implementation of it in hopes that either it is
implemented as a php function or just communicated to the users.

function period_diff($in_dateLow, $in_dateHigh) {
    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;
}

The idea is pretty trivial, you just start counting using strtotime
until you get to the upper date, moving along by months.  The people
that suggest

$date/(60*60*24*30) are severally wrong and that can lead to many
bugs.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <[EMAIL PROTECTED]>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
[Frodo]: "I wish it need not have happened in my time." 
[Gandalf]: "So do I, and so do all who live to see such times. 
But that is not for them to decide. All we have to decide is 
what we do with the time that is given to us.'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to