Page 1 of 1

DATEDIFF using mysql-php, it simple

Posted: Mon Jan 01, 2007 7:31 am
by paresh
Hello experts,

i have following query with me,

"SELECT floor(datediff(CURDATE(), usr.birth_date))/365) as age FROM user_details as usr

Which gives me the number of days between current date and user birth date. Am dividing the result by 365, and get floor() of it.

NOW THE PROBLEM is:

AM dividing the result by 365 blindly, without keep in mind that, thare may be leap year in between this (leep year have 365 days). Since it gives me wrong result (with difference of 5 days).

Please reply,
Am waiting for it.

Thanks n regards,
paresh@panaceatek.com

Posted: Mon Jan 01, 2007 11:39 am
by feyd
You could perform some additional math. Specifically, using a comparison between the days and months of each combined with a difference of the years.