android sqlite 日期查询
例1. select datetime('now'); 结果:2006-10-17 12:55:54 例2. select datetime('2006-10-17'); 结果:2006-10-17 12:00:00 例3. select datetime('2006-10-17 00:20:00','+1 hour','-12 minute'); 结果:2006-10-17 01:08:00 例4. select date('2006-10-17','+1 day','+1 year'); 结果:2007-10-18 例5. select datetime('now','start of year'); 结果:2006-01-01 00:00:00 例6. select datetime('now','start of month'); 结果:2006-10-01 00:00:00 例7. select datetime('now','start of day'); 结果:2006-10-17 00:00:00 例8. select datetime('now','+10 hour','start of day','+10 hour'); 结果:2006-10-17 10:00:00 例9. select datetime('now','localtime'); 结果:2006-10-17 21:21:47 例10. select datetime('now','+8 hour'); 结果:2006-10-17 21:24:45
数据库中有
integer text
id datatime
1 2010-01-01
2 2010-01-02
2 2010-01-03
2 2010-01-04
2 2010-01-05
2 2010-01-06
2 2010-01-07
select * from a where datatime>"2010-01-04"
查询结果
2 2010-01-05
2 2010-01-06
2 2010-01-07
-----------------------
+------------+----+
6 rows in set
sqlite> select * from a where datime>'2000-01-01';
1 - no such column: datime
sqlite> select * from a where datt
ime>'2000-01-01';
+------------+----+
| dattime | id |
+------------+----+
| 2000-01-02 | 2 |
| 2000-01-03 | 3 |
| 2015-09-09 | 4 |
| 2012-05-05 | 5 |
+------------+----+
4 rows in set
sqlite> select * from a where dattime>'2000-01-01';
+------------+----+
| dattime | id |
+------------+----+
| 2000-01-02 | 2 |
| 2000-01-03 | 3 |
| 2015-09-09 | 4 |
| 2012-05-05 | 5 |
| 4534 | 6 |
+------------+----+
5 rows in set
sqlite> select * from a where dattime>'2000-01-01' and datime != '4534';
1 - no such column: datime
sqlite> select * from a where dattime>'2000-01-01' and dattime != '4534';
+------------+----+
| dattime | id |
+------------+----+
| 2000-01-02 | 2 |
| 2000-01-03 | 3 |
| 2015-09-09 | 4 |
| 2012-05-05 | 5 |
+------------+----+
4 rows in set