|
Posted by Alan Little on 02/01/06 03:34
Carved in mystic runes upon the very living rock, the last words of
<phillip.s.powell@gmail.com> of comp.lang.php make plain:
> Dangit I thought I could do THIS simple task today and even this is
> beyond me!! :(
>
> [code]
> <?= date(time()) - date(strtotime($result[0]->birth)) ?>
> [/code]
>
> This is completely wrong, but what IS right? I'm stumped!
Assuming the DOB values are in $Year, $Month and $Day:
$ThisYear = date('Y');
// Get this year as YYYY
$Age = $ThisYear - $Year;
// Subtract birth year
if (date('z') < date('z', strtotime("$ThisYear-$Month-$Day"))) {
$Age--;
}
// date('z') = day of the year, 0-366
// If today is less than the birthday, decrement $Age
--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
[Back to original message]
|