2010-02-22 5 views
36

생년월일이 포함 된 sqlite 테이블이 있습니다. 나는 세 이상 30 나는 다음과 같은 시도이다 레코드를 선택하는 쿼리를 실행하고 싶지만 그것이 작동하지 않습니다날짜에 조건이있는 sqlite 선택

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

답변

56

이 같은 어떤 것을 사용할 수있다 :

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

것은 그냥 dateofbirth를 사용 date(dateofbirth)를 사용 SQLite는 V3.7.12 이상

망가를 사용하는 경우. 그래서 쿼리는 다음과 같습니다

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

구글에서 온 모든 사람들 : 이제 sqlite v3.7.12에서는 더 이상 작동하지 않습니다. 'date (dateofbirth)'를 사용하지 말고'dateofbirth' 만 좋을 것입니다. – wecing

2

날짜 형식을 사용하여 작성하십시오 'YYYY-MM- 당신은 SQLite는 특정 구문을 찾을 필요가있다

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

: DD '

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

더 programic 방법은 다음과 같이 될 것이다.

+0

선택 * 생년월일이> '1980년 1월 1일' 2010 년 – Thunder

+2

을 뒤로 작동하지 않습니다 MYTABLE에서 'select * from mytable where dob> '1980-01-01'이 작동하지 않을 수도 있지만, 현재이 명령은'sqlite3'에서 완벽하게 작동합니다. – Shane

+1

나는'sqlite3'에서 잘 작동한다고 동의한다. –

19

을 마법 문서를 사용 the sqlite website에서 :

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