0
我有我的數據存儲在一個字段「日期」與字符串格式,我想查詢該表以顯示結果誰擁有某一年包含指定年。查詢結果至少有一個字符串格式的日期
我的問題是如何讓這一年從字符串,我目前有:
public Cursor getExpensesByYear() {
String sql = "SELECT * FROM " + TABLE_EXPENSE + " WHERE strftime('%Y', date) = '2015'";
Cursor cursor = getReadableDatabase().rawQuery(sql, null);
// String inputString = cursor.getString(5);
// DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
// try {
// Date inputDate = dateFormat.parse(inputString);
// } catch (ParseException e) {
// e.printStackTrace();
// }
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
它只是犯規返回任何數據。
請參閱[文檔](http://stackoverflow.com/documentation/sqlite/5252/data-types/18688/date-time-types)。 –