sqlite选择条件日期

时间:2010-02-22 06:37:55

标签: sql database sqlite date

我有一个带有出生日期的sqlite表。我想执行一个查询来选择年龄超过30岁的记录。 我尝试了以下但它不起作用:

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

3 个答案:

答案 0 :(得分:68)

可以使用这样的东西:

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');

如果您使用的是Sqlite V3.7.12或更高版本

请勿使用date(dateofbirth)使用dateofbirth。所以你的查询看起来像这样:

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

答案 1 :(得分:21)

使用the sqlite website处的魔术文档:

select * from mytable where dob < date('now','-30 years');

答案 2 :(得分:5)

尝试使用日期格式'YYYY-MM-DD'

进行书写
select * from mytable where dob > '1980-01-01'

更具规划性的方式是这样的:

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

您需要找到sqlite的特定语法。

相关问题