RE: [PHP] how to find difference in months and years?

From: Date: Sat, 01 Jul 2000 11:24:11 +0000
Subject: RE: [PHP] how to find difference in months and years?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-4201@lists.php.net to get a copy of this message
A long time ago someone posted a rather ugly but effective way to cacluate the # of days in a given month.... Perhaps this will help: <?php function DaysInMonth($month,$year){ return 31-((($month-(($month<8)?1:0))%2)+(($month==2)?((!($year%((!($year%100))?400 :4)))?1:2):0)); } ?> Like I said, it's not the prettiest function i've ever seen (but it's kinda cool if you ask me) -- at least it works John -----Original Message----- From: Daevid Vincent [mailto:DayWalker@TheMatrix.com] Sent: Friday, June 30, 2000 7:18 PM To: php-general Subject: [PHP] how to find difference in months and years? > 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#4201) next »