Greetings All!
I'm trying to figure out why a discrepancy is occuring within a select statement I'm running.
SELECT per_ID,CONCAT(per_FirstName,' ',per_LastName) AS Name, CONCAT(per_BirthMonth,'/',per_BirthDay,'/',per_BirthYear) AS 'Birth Date',
((TO_DAYS(NOW())-TO_DAYS(CONCAT(per_BirthYear,'-',per_BirthMonth,'-',per_BirthDay)))/365) AS 'Exact Age',
FLOOR((TO_DAYS(NOW())-TO_DAYS(CONCAT(per_BirthYear,'-',per_BirthMonth,'-',per_BirthDay)))/365) AS 'Age in Years'
FROM person_per
WHERE
DATE_ADD(CONCAT(per_BirthYear,'-',per_BirthMonth,'-',per_BirthDay),INTERVAL 15 YEAR) <= CURDATE()
AND
DATE_ADD(CONCAT(per_BirthYear,'-',per_BirthMonth,'-',per_BirthDay),INTERVAL 16 YEAR) >= CURDATE() ORDER BY per_LastName, per_FirstName
Now everybody in my results for this search (everybody in the database between the ages of 15 and 16) looks fine... except for one kid.... whose birthday is tomorrow (but note: this problem has been showing up incorrectly for several days):
person birthdate exact age age
Michael McCarter 11/11/1987 16.01 16
The kid is still 15. This problem was reported to me by a user last week. He's showing up as 16 ! Why ???
Why does:
((TO_DAYS(NOW())-TO_DAYS(CONCAT(per_BirthYear,'-',per_BirthMonth,'-',per_BirthDay)))/365)
come out to 16 instead of 15???
I've googled to try to find a different equation to use in calculating age, but I haven't found anything else.
Could it be leap years or something?
For technical reasons, I need MySQL to do the math and not php.
Thanks!
-= Dave =-