我試圖從一年前的當前日期之間獲取來自sqlite數據庫的數據。我使用了下面的代碼。但它沒有提供數據。考慮當前日期是25-10-2013。有數據爲25-09-2013。但是裏面的代碼不會執行。我沒有得到代碼中的錯誤。同樣的方式,我用了3個月前和6個月前,他們工作得很好。如何在Android中的sqlite中獲取當前日期和上一年當前日期之間的值
DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
Calendar cal11 =Calendar.getInstance();
cal11.add(Calendar.MONTH, -12);
String one_year_before = cur_format1111.format(cal11.getTime());
Log.v("one_year_before", one_year_before);
查詢來選擇數據:
Cursor cur21 = db.rawQuery("SELECT * FROM " + TIMER_TABLE
+ " WHERE cur_date BETWEEN ? AND ?", new String[] {
one_year_before, cur_form_Date });
if (cur21 != null) {
if (cur21.moveToFirst()) {
do {
has_valuesyear = true;
String reader_name_db_service = cur21.getString(cur21
.getColumnIndex("username"));
Log.v("reader_name_db_service21",
reader_name_db_service);
if (reader_name_db
.equalsIgnoreCase(reader_name_db_service)) {
String tot_reading_time = cur21.getString(cur21
.getColumnIndex("tot_reading"));
Log.v("tot_reading_time21", tot_reading_time);
String cur_date = cur21.getString(cur21
.getColumnIndex("cur_date"));
Log.v("cur_date21", cur_date);
one_year_set.add(reader_name_db_service + "~"
+ cur_date + "~" + tot_reading_time);
}
} while (cur21.moveToNext());
}
}
cur21.close();
db.close();
什麼是'format1111'? –
這是dd-MM-yyyy – Manikandan