note 45204 deleted from function.date by aidan

From: Date: Tue, 07 Sep 2004 06:58:46 +0000
Subject: note 45204 deleted from function.date by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76126@lists.php.net to get a copy of this message
Note Submitter: frugal at tildefrugal dot net ---- Thanks for posting that code for figuring out someone's age, I was just looking for a way to do that. However, I noticed two problems with your code. You have: if($monthdiff < 0 || $daydiff < 0){ But it should be if($monthdiff <= 0 && $daydiff < 0){ The way you had it, only 1 condition had to be true in order for it to be before your birthday this year but you need both to be true (has to be both before your month of birth and day of birth). The way you had it, if you were born late in the month (as I am), then it will say you're a year younger every month until the day of the month is the same or greater than your day of birth. I also added in the <= 0 for the monthdiff because otherwise it doesn't properly handle your age when it's in your month of birth but before your birthday. Other than that, thanks for posting this because I just could not get my head wrapped around how to write this myself!

« previous php.notes (#76126) next »