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



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);
$age = date("Y") - date("Y",$birthdate);
if ((date("n") < date("n",$birthdate)) or ((date("n") ==
date("n",$birthdate)) and (date("j") < date("j",$birthdate)))) {
$age--;
}

echo $age;

?>

--
Kim André Akerø
- kimandre@xxxxxxxxxxxxxxxxxx
(remove NOSPAM to contact me directly)
.



Relevant Pages

  • Re: Leave it to the French
    ... > CAPITALIZE THAT "I" DANGIT! ... You like being a proper noun, ... Prev by Date: ...
    (microsoft.public.cert.exam.mcse)
  • Re: Thread hijack
    ... > (And I _have_ a puppy, dangit!) ... Oh man you're baaaaad. ... Tara ... Prev by Date: ...
    (rec.pets.dogs.breeds)
  • Re: OT: Thursday Namedropping
    ... DANGIT WAYNE!!!! ... - He who laughs last probably made a backup. ... Prev by Date: ...
    (microsoft.public.cert.exam.mcse)