Reply to Re: How do you get someone's age from DOB?

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация