简体   繁体   中英

How to get Age in Months using BirthDate column by MySQL query?

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


select * from [table] 
where 
BirthDate>= date_sub(curdate(),interval 600 MONTH)
and 
BirthDate<= date_sub(curdate(),interval 400 MONTH)
SELECT * FROM that_table
WHERE CURRENT_TIMESTAMP BETWEEN (BirthDate + INTERVAL 400 MONTH) AND (BirthDate + INTERVAL 600 MONTH)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM