我创建了一个使用Sqlite数据库的应用程序。我想显示从今天到过去7天的数据。不应选择上面的数据。所以为此,我写了一个查询,但它似乎没有起作用。在列表中,我收到了过去7天以上的数据
代码
public ArrayList<DbModel> getRecentDocs() {
database = getWritableDatabase();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String todate = dateFormat.format(date);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -7);
Date todate1 = cal.getTime();
String fromdate = dateFormat.format(todate1);
alGetRecentFiles = new ArrayList<DbModel>();
dbModel = new DbModel();
String query = "Select * From " + saveFileTable + " where " + postedOn + " >= " + fromdate;
Cursor c = database.rawQuery(query, null);
while (c.moveToNext()) {
dbModel = new DbModel(c.getString(c.getColumnIndexOrThrow(userId)), c.getString(c.getColumnIndexOrThrow(docId)), c.getString(c.getColumnIndexOrThrow(fileName)), c.getString(c.getColumnIndexOrThrow(fileExt)), c.getString(c.getColumnIndexOrThrow(title)), c.getString(c.getColumnIndexOrThrow(filePath)), c.getString(c.getColumnIndexOrThrow(postedOn)), c.getString(c.getColumnIndexOrThrow(favourite)));
alGetRecentFiles.add(dbModel);
}
c.close();
database.close();
return alGetRecentFiles;
}