DATEDIFF using mysql-php, it simple

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
paresh
Forum Newbie
Posts: 6
Joined: Mon Oct 09, 2006 3:46 am
Contact:

DATEDIFF using mysql-php, it simple

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

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