0

For a database table containing int fields date, month and year, what is the best way to query rows greater than a specified date?

Sandah Aung
  • 6,156
  • 15
  • 56
  • 98

2 Answers2

2

You can do:

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

See sqlite select with condition on date

Community
  • 1
  • 1
Leon
  • 867
  • 7
  • 13
1

With simple arithmetic, you can make a selection like this:

SELECT * FROM t WHERE year*10000+month*100+day>20131021;
LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46
  • Even though there is a better answer than yours for the Android platform, I find your answer useful for the server code for which I will be using your query. Thanks for your answer. – Sandah Aung Oct 21 '13 at 08:28
  • @SandahAung Humm... This solution is lightweight - doesn't involve much logic neither function calls - and deals with "int fields". How does accepted solution apply??? – LS_ᴅᴇᴠ Oct 21 '13 at 08:43
  • The accepted solution looks better to my boss who tends to prefer function calls to programmer-supplied code. (He thinks API functions are cleaner and less err0r-prone.) The boss who oversees server-side coders doesn't mind though so I'm using your code on the server side. – Sandah Aung Oct 21 '13 at 09:00