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!! :(

If you're using mysql to get the "birth" field, why not add a field in
the query:
FLOOR((CURDATE() - DOB)/10000) AS age

> [code]
> <?= date(time()) - date(strtotime($result[0]->birth)) ?>
> [/code]
>
> This is completely wrong, but what IS right? I'm stumped!

This depends on how your server handles timestamps. For instance, does
it support negative ones (before 1970)? I've found using SQL queries to
calculate age generally work much better as it seems to be consistent
between platforms/servers.

--
Justin Koivisto, ZCE - justin@xxxxxxxxx
http://koivi.com
.



Relevant Pages

  • Re: How do you get someones age from DOB?
    ... Phil ... Justin Koivisto wrote: ... >> Dangit I thought I could do THIS simple task today and even this is ... > calculate age generally work much better as it seems to be consistent ...
    (comp.lang.php)
  • Strange Behaviors
    ... I can take my app and install it on multiple ... I am using MySQL 4.0.17 with VB.NET 2003. ... column that stores the Age. ...
    (microsoft.public.dotnet.languages.vb)
  • Age from date field?
    ... date column in mysql... ... as long as I can expect it to work on paid hosts... ... Notice that I'm only looking for the age in years... ... // DvDmanDT ...
    (php.general)
  • Joining and then ordering by a common column
    ... I have mysql 4.0.something (so I can't do subselects). ... I think this is a common question: ... The "age" column is unqualified. ...
    (comp.databases)
  • Re: [PHP] Age from birthdate?
    ... AS age ... will work for MySQL, where "dob" is your DATE date of birth column. ...
    (php.general)