note 45204 added to function.date
| From: | frugal at tildefrugal dot net | Date: | Sun, 29 Aug 2004 19:11:28 +0000 |
| Subject: | note 45204 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75585@lists.php.net to get a copy of this message | ||
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!
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45204
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45204&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45204&report=yes
Search -- http://master.php.net/manage/user-notes.php