Question : calculate age in mysql

Let's say I have the following fields in users table bday, bmonth, byear and age. What mysql query calculates age of users and updates the age field on two decimals like 25.45 on all records?
Thank you.

Answer : calculate age in mysql

It's not a good idea to store bmonth, byear or age, those should all be calculated from the single bdate column.  

You would be better off writing a query to get that information using a query.  That way do you don't have to worry about updating the database on a regular basis.  

As soon as you update the table the data becomes out of date.  

Your query will always be up to date when ever you run it.

To Calculate Age:
SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),date_column)), '%Y')+0 as Age from table;

To Get the Bmonth:
Select monthname(date_column) from table;

To get the Byear:
Select year(date_column) from table;
 
Random Solutions  
 
programming4us programming4us