Re: How do you get someone's age from DOB?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

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

From: Justin Koivisto <justin@koivi.com>
Date: Mon Jan 30 2006 - 21:19:03 CET

comp.lang.php wrote:
> Please go over this line by line, you completely lost me.
>
> Phil
>
> Kim André Akerĝ wrote:
>> comp.lang.php wrote:
>>
>>> 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!
>> More like this:
>> http://james.cridland.net/code/age.html
>>
>> In your case, the code would be:
>>
>> <?php
>>
>> $birthdate = strtotime($result[0]->birth);

unix timestamp of birth date (midnight if no time is included) - if on
windows server & date is before 1970, the value will be "-1" - nothing
that you can really use.

>> $age = date("Y") - date("Y",$birthdate);

The current 4-digit year minus the 4 digit birth year (assuming that the
strtotime call worked)

>> if ((date("n") < date("n",$birthdate)) or ((date("n") ==
>> date("n",$birthdate)) and (date("j") < date("j",$birthdate)))) {

if (
    numeric month of now < numeric month of birth date
  or
    numeric month of now == numeric month of birth date
      and
    day of month now < day of month birth date

>> $age--;

Take off a year because they haven't hit their birthday of this year yet

>> }
>>
>> echo $age;

The number of years old they are

-- 
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Received on Tue Feb 7 21:07:55 2006