I have this on my WHERE clause
dob <= DATE_SUB(CURDATE(),INTERVAL 1 YEAR) AND dob >= DATE_SUB(CURDATE(),INTERVAL 19 YEAR)
It works alright,it searches a persons by age based on their DOB,
however there is some precision issues.
Consider the following:
1 to 19 = 397
20-25 = 1350
26- 30 = 1139
31-35 = 601
36-40 = 346
41-45 = 218
46- 50 = 154
51-55 = 139
56-60 = 65
61-85 = 78 Total = 4487
If I use the same method but search for 1 – 85 return 5607
I am puzzled but then again dates are my weakness so any help would be appreciated.
Oh, I think when you do
DATE_SUB(CURDATE(),INTERVAL 19 YEAR)and thenDATE_SUB(CURDATE(),INTERVAL 20 YEAR)You miss people in there 19th years, so you’re missing the people in there 19th, 26th, 30th, 35th … etc
It should be
dob < DATE_SUB(CURDATE(),INTERVAL 1 YEAR) AND dob >= DATE_SUB(CURDATE(),INTERVAL 19 YEAR)And then
dob < DATE_SUB(CURDATE(),INTERVAL 19 YEAR) AND dob >= DATE_SUB(CURDATE(),INTERVAL 25 YEAR)edit :