Android Sqlite - 选择1小时前插入的行



我在Android Sqlite上工作,我尝试获取1小时前插入的行。但是它没有返回任何内容,我通过 cursor.count() 检查了

我尝试了以下查询

String[] columns = new String[] { KEY_ID, KEY_CONTENT1, KEY_CONTENT2,
                KEY_CONTENT3, KEY_CONTENT4, KEY_CONTENT5, KEY_CONTENT6};
cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, KEY_CONTENT3               + "< " + "DATETIME('NOW', '-1 hours')", null, null, null, null);

和另一个查询

String selectRow = "select *  FROM detail1 WHERE content3 < DATETIME('NOW', '-1 hours');";
Cursor cursor = sqLiteDatabase.execSQL(selectRow);

和另一个查询

String selectRow = "select *  FROM detail1 WHERE content3 < DATETIME('NOW', '-1 hours');";
cursor = sqLiteDatabase.rawQuery(selectRow,null);

此查询对我有用

String selectRow = "select *  FROM detail1 WHERE content3 > DATETIME('NOW', '-1 hours');";
Cursor cursor = sqLiteDatabase.execSQL(selectRow);
DATETIME('NOW', '-1 hours');" 

此函数在此 2014-01-04 中返回时间, 在数据库中2014-01-04 10:24:21有这种格式。这里只有2014比较而不是完整的日期。更好的应用,我建议使用时代

尝试下面的查询,它将为您提供秒数差异

SELECT (strftime('%s','now')/60) - (strftime('%s',content3)/60);

最新更新