我想检索所有记录,在与当前日期前 3 天之前和之后的 Parsed_Reminder_Date 进行比较后,在我的数据库中 Parsed_Reminder_Date 是一个用于保存日期的列,它的数据类型很长,这是我的代码
Calendar calendar = Calendar.getInstance(); // This will give you the current time.
// Removing the timestamp from current time to point to todays date
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.DATE, -3); // Will subtract 3 days from today.
Date beforeThreeDays = calendar.getTime();
calendar.add(Calendar.DATE, 6); // Will be your 3 days after today
Date afterThreeDays = calendar.getTime();
long threedaybefore=beforeThreeDays.getTime() ;
long threedayafter=afterThreeDays.getTime() ;
Log.i("beforeThreeDays",Long.toString(threedaybefore));
Log.i("afterThreeDays",Long.toString(threedayafter));
String Reminder_Main = "Reminder_Main",ID = "ID", Reminder_Date = "Reminder_Date", Parsed_Reminder_Date = "Parsed_Reminder_Date";
Cursor remindercursor = sdb
.rawQuery(
"select Reminder_Id,Reminder_Type,Reminder_Time,Reminder_Date,Reminder_Alert,Reminder_Done,Reminder_byodometer,Reminder_bydate from "
+ Reminder_Main
+ " where "
+ ID
+ " = ? AND "
+ Parsed_Reminder_Date
+ " >= ? OR "
+ Parsed_Reminder_Date
+ " <= ? ",
new String[] {summaryid, Long.toString(threedaybefore), Long.toString(threedayafter)});
remindercursor.moveToFirst();
当我执行此操作时,我得到了所有我不想要的记录,请纠正我哪里出错了。