0

I have field date_of_birth....
If I want to calculate age
"select floor((to_days(curdate())-to_days(date_of_birth))/5) as age
from table"
So I can use the above one...

instead of executivg this at every time I want,
Is it possible to create a field named age with above structure so If I store the date_of_birth, I can retrieve age automatically?

Edited by harikrishna439: n/a

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by urtrivedi
0

MySql does not support computed columns, but you can write an insert/update trigger to fill in the age column of your table.

0

you can create view where you can calculate age using above formula and other required columns,
Then you many use your view everywhere, now you just have to use column name age, no need to give formula again.

0

Run following sql queries in phpmyadmin sql window. This is how you can create view.

create view  mytableview  as select col1,col2,col3, col4 floor((to_days(curdate())-to_days(date_of_birth))/5) as age
from table

This is how you can use view, if you update date of birth view will give the latest value. no need recalucate or update.

select col1,col2,col3,age from mytableview

Edited by urtrivedi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.