Re: Returning Age instead of Birthdate
| From: | 1LT John W. Holmes | Date: | Tue, 15 Oct 2002 18:31:59 +0000 |
| Subject: | Re: Returning Age instead of Birthdate | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-22421@lists.php.net to get a copy of this message | ||
> Is there an easy way to have MySQL return someone's age based on their
> birthdate? For some reason I just can't figure this one out.
select year(current_date) - year(dob) -
(if(dayofyear(dob)>dayofyear(current_date),1,0)) as Age from yourtable ...
where dob is your date of birth column. current_date is a mysql constant, so
it can be left just like that.
---John Holmes...