I have stored date of birth of my users into my database..
I want to calculate their age according to the database dob field...
Please help me..

Thanks..

SELECT DATE_FORMAT( FROM_DAYS( DATEDIFF( NOW( ) , "1978-03-28" ) ) , '%Y' ) +0 AS age

Even this works. Just replace the date (1978-03-28) with the date of birth column.

Hi Naveen...

I have done a code with your reference..
But i got error in mysql:

Error
SQL query:

"SELECT fname,date,curdate(),(YEAR(curdate())-YEAR(date))-(RIGHT(curdate(),5)<RIGHT(date,5)) AS age FROM date_profiles ORDER BY fname";

MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"SELECT fname,date,curdate(),(YEAR(curdate())-YEAR(date))-(RIGHT

date is a mysql reserved keyword. You should use `` around reserved keyword fields to make them work.

date is a mysql reserved keyword. You should use `` around reserved keyword fields to make them work.

If dont mind...
Please edit my code and resend...
Thank you...

Then maybe something is wrong with your query.
I tried it and it worked !

SELECT uname,datej,curdate(),(YEAR(curdate())-YEAR(datej))-(RIGHT(curdate(),5)<RIGHT(datej,5)) AS age FROM members ORDER BY uname
Comments
smart answer

i got the correct output...
What my mistake is:
i have declared dob with varchar,after i changed it to date,correct output came...

Thank you naveen....

This article has been dead for over six months. Start a new discussion instead.