how to find difference in months and years?

From: Date: Fri, 30 Jun 2000 23:17:47 +0000
Subject: how to find difference in months and years?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-4200@lists.php.net to get a copy of this message
> Actually, it has a really powerful date system. > date()/time()/mktime() are arguably more powerful > than anything MySQL has and considerably faster. Use mktime() to > turn a textual date into a Unix > timestamp, which is simply stored as seconds since an epoch: > > 1 day = 24 * 60 * 60 seconds = 86400 > > To find the number of days between two dates, just subtract one > from the other and divide by 86400: > > $DiffInSeconds = (mktime(0,0,0, 10, 1, 2000) - mktime(0,0,0, > 06, 1, 2000)) > > $DiffInDays = $DiffInSeconds / 86400 So, this tells me the difference in days, but how can I tell how many months or years between two dates, since they'll have a different number of days in each month? I can't just divide the $DiffInDays by 30 because some months have 28,29,30, or 31 days in them.

« previous php.general (#4200) next »