Reputation: 18590
First I asked this question to do this and accepted answer helped me. But Now the problem is that I have to calculate age in months.
Question:
I have a BirthDate column in MySQL database table to store user's date of birth. Now I have form in html/php with two fields(1. Age From 2. Age To).
If user want to get all users where their ages are between 400 months and 600 months, Is it possible to do this with MySQL query using BirthDate column.
Thanks
Upvotes: 1
Views: 513
Reputation: 272236
SELECT * FROM that_table
WHERE CURRENT_TIMESTAMP BETWEEN (BirthDate + INTERVAL 400 MONTH) AND (BirthDate + INTERVAL 600 MONTH)
Upvotes: 3
Reputation: 2817
select * from [table]
where
BirthDate>= date_sub(curdate(),interval 600 MONTH)
and
BirthDate<= date_sub(curdate(),interval 400 MONTH)
Upvotes: 4