복붙노트

[SQL] 날짜 조건을 선택 SQLite는

SQL

날짜 조건을 선택 SQLite는

나는 생년월일과 sqlite가 테이블에 있습니다. 나는 나이가 많은 30보다 어디 레코드를 선택하는 쿼리를 실행하고 싶습니다. 나는 다음을 시도했지만 작동하지 않습니다 :

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

해결법

  1. ==============================

    1.이런 식으로 뭔가가 사용될 수있다 :

    이런 식으로 뭔가가 사용될 수있다 :

    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 이상을 사용하는 경우

    그나마 사용 날짜 (생년월일 (DateOfBirth)는) 단지 생년월일 (DateOfBirth)를 사용합니다. 쿼리는 다음과 같이 보일 것이다 그래서 :

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

    2.SQLite는 웹 사이트에서 마법 문서를 사용 :

    SQLite는 웹 사이트에서 마법 문서를 사용 :

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

    3.날짜 형식 'YYYY-MM-DD'를 사용하여 작성하십시오

    날짜 형식 'YYYY-MM-DD'를 사용하여 작성하십시오

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

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

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

    당신은 SQLite는 특정 구문을 찾을 필요가있다.

  4. from https://stackoverflow.com/questions/2309227/sqlite-select-with-condition-on-date by cc-by-sa and MIT license