sqlite select with condition on date

匿名 (未验证) 提交于 2019-12-03 02:47:02

问题:

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 work:

select * from mytable where dob > '1/Jan/1980' select * from mytable where dob > '1980-01-01'

回答1:

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) 

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 


回答2:

Using the magic docs at the sqlite website:

select * from mytable where dob 


回答3:

Try writing using the date format 'YYYY-MM-DD'

select * from mytable where dob > '1980-01-01'

A more programic way would be something like this:

select * from mytable where datediff(dob, now()) > 30

You'll Need to find specific syntax for sqlite.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!