sqlite select with condition on date

前端 未结 3 1034
一生所求
一生所求 2020-11-29 06:03

I have an sqlite table with Date of Birth. I would like to execute a query to select those records where the age is more than 30. I have tried the following but it doesn\'t

3条回答
  •  死守一世寂寞
    2020-11-29 06:23

    Some thing like this could be used:

    select dateofbirth from customer Where DateofBirth  BETWEEN date('1004-01-01') AND date('1980-12-31');  
    select dateofbirth from customer where date(dateofbirth)>date('1980-12-01');
    select * from customer where date(dateofbirth) < date('now','-30 years');
    

    If you are using Sqlite V3.7.12 or greater

    Dont use date(dateofbirth) just use dateofbirth. So your query would look like this:

    select * from customer where dateofbirth < date('now','-30 years');
    

提交回复
热议问题