On 06/04/10 11:45, James Bensley wrote:
I am trying to execute the following MySQL statement and am coming up a croppa'
SELECT name FROM `visitor` WHERE dob = DATE_SUB(CURDATE(), INTERVAL 21 YEAR)
If I read this correctly, you're looking for someone who is exactly 21 years old. Ie today is their 21st birthday. For example, right now: SELECT DATE_SUB(CURDATE(), INTERVAL 21 YEAR); .. gives me "1989-04-06" Presumably SELECT name FROM `visitor` WHERE dob <= DATE_SUB(CURDATE(), INTERVAL 21 YEAR) .. would get what you want?
SELECT name FROM `visitor` WHERE dob BETWEEN DATE_SUB(CURDATE(), INTERVAL 21 YEAR) AND DATE_SUB(CURDATE(), INTERVAL 30 YEAR)
to get everyone who is between X and Y years old. Do people think the problem is in my statement or my database?
Have you tried this? It looks pretty close to me. I am, of-course, making assumptions about the nature of your dob field; I assume it is a DATE? -- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450 Registered in England (0456 0902) @ 13 Clarke Rd, Milton Keynes, MK1 1LG