Exactly, that's what rudy's code does. Of course, you'll have to change some table and field names
Code:
select
id
, name
, birth
, year(current_date)
- year(birth)
- case when month(current_date)
> month(birth)
then 0
when month(current_date)
< month(birth)
then 1
when dayofmonth(current_date)
< dayofmonth(birth)
then 1
else 0 end as age
from stu
Btw, once you save the date of birth, it doesn't make much sense storing the age in your table as well, since you'd have to recalculate it everytime again anyway. Just calculate it when you select the data from the table.
Bookmarks