nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
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.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
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)
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
date is a mysql reserved keyword. You should use `` around reserved keyword fields to make them work.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
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...
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
replace date with `date`.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
date is my database field, and i declared it as varchar...
Is it a problem?
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
Yes. date is a mysql keyword and whatever the datatype is, its still a problem.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
Yep..
I changed my date to date1..
Still i got the error...
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
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
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
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....
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
Hello nav..
In the above code CURDATE is database field or its todays date...tel me.
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356