For a database table containing int fields date, month and year, what is the best way to query rows greater than a specified date?
Asked
Active
Viewed 2,465 times
0
-
what DB implementation (i.e. Oracle, MySQL?) – Leon Oct 21 '13 at 08:04
-
Possible duplicate of [sqlite select with condition on date](https://stackoverflow.com/q/2309227/608639) – jww Oct 31 '19 at 05:44
2 Answers
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');
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