我有一个sqlite表与出生日期。我想执行一个查询,选择那些记录,年龄超过30 我曾尝试以下,但它不工作:sqlite select与日期条件
select * from mytable where dob > '1/Jan/1980'
select * from mytable where dob > '1980-01-01'
我有一个sqlite表与出生日期。我想执行一个查询,选择那些记录,年龄超过30 我曾尝试以下,但它不工作:sqlite select与日期条件
select * from mytable where dob > '1/Jan/1980'
select * from mytable where dob > '1980-01-01'
一些像这样的事情,可以使用:
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');
尝试使用的日期格式写“YYYY-MM- DD”
select * from mytable where dob > '1980-01-01'
更programic的方法是这样的:
select * from mytable where datediff(dob, now()) > 30
你需要找到sqlite的特定语法。
使用魔法文档在the sqlite website:
select * from mytable where dob < date('now','-30 years');
所有从google来到这里的人:现在不再使用sqlite v3.7.12了;不要使用'date(dateofbirth)',只是'dateofbirth'会很好。 – wecing 2013-01-12 22:16:14