note 58151 deleted from function.mktime by derick
| From: | derick@php.net | Date: | Sun, 24 Sep 2006 11:52:55 +0000 |
| Subject: | note 58151 deleted from function.mktime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117504@lists.php.net to get a copy of this message | ||
Note Submitter: eidolon at idealsound dot ca
----
There was a birthdate calculator posted above which from reading the code seems flawed in my logic.
Oddly, most code I see to calculate birthdates tries to use the difference between the years to find
it's result, which can be flawed (if my birthday is Jan 10th and I'm 19, and its Jan 5th,
these scripts might still think I am 20). Basically this creates a timestamp with the desired
birthdate and only checks if the given birthdate has passed this year yet or not. Simple &
reliable age in years!
Here's the code I use to do this, which, yes, could be better written:
$bd = mktime(0,0,0,$month,$day,$year);
if (date("n") > intval($month)) {$before = FALSE;}
if (intval(date("j")) >= intval($day)) {$before = FALSE;}
else {$before=TRUE;}
if ($before == TRUE) { $age = (date("Y")-$year)-1; }
else { $age = (date("Y")-$year); }