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



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@xxxxxxxxx
http://koivi.com
.



Relevant Pages

  • Gettin My 1st id
    ... 2- My name was changed twice while i was young and the deed poll ... 3- My Birth certificates was also lost ... I'm 18 now) i filled it in with my birth name not my current name. ...
    (uk.legal)
  • Re: Lost Birth Certificate
    ... Lucy wrote: ... I have a green card. ... > You should be able to get a replacement birth certificate from wherever your ... > I lost mine (actually, I sent it to immigration at one point in the green ...
    (misc.immigration.usa)
  • Re: Flowers - spoilerish Tuesday 15 Dec
    ... Jenny M Benson wrote: ... person who gave it, with whom I have long since lost contact, but also ... of the birth of my cat Fang, in the middle of our afternoon tea. ...
    (uk.media.radio.archers)
  • Re: M3 bands allowed to use
    ... > Nothing lost there then ... > celebrating the birth of a fictitious character ...
    (uk.radio.amateur)
  • Re: Ive seen things you people wouldnt believe...
    ... You need either a birth certificate or immigration documentation and ... filled out a birth certificate but when she tried to get a copy it was ... been lost by the county, lost when the records were centralized by the ... There is a time limit on challenging the presumption of citizenship in those sort of cases, ...
    (rec.arts.sf.fandom)