0

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..

3
Contributors
14
Replies
15
Views
8 Years
Discussion Span
Last Post by nav33n
0
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.

0

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

0

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

0

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...

1

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
0

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 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.