mysql - How to find list of people whose age is between a range? -


i have situation have date-of-birth stored in database eg. 1990/03/15. want find out info. of records age between 20 & 30. how should write query?

i have tried this: age of candidates using query:

select timestampdiff(year,dob,curdate()) age `profile` 

how use list of candidates between age 20 & 30?

the now() gives current date. now, date 20 , 30 years older, can following:

date_sub(now(), interval 20 year) ,  date_sub(date, interval 30 year) 

now remaining query simple. is,

select * person  dateofbirth between date_sub(now(), interval 20 year)                    , date_sub(date, interval 30 year) 

Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -