我想获得11月至11月的所有价值。 我创建了类似的东西:
public static List<Plan> getPlanListByMonth(SQLiteDatabase db, DateTime date) {
String where = "strftime('%m', '"+"date"+"') = " +
"'"+"11"+"'";
Cursor cursor = db.query(TABLE_NAME, null, where,
null, null, null, null, null);
return getPlanList(cursor);
}
private static List<Plan> getPlanList(Cursor cursor) {
List<Plan> PlanList = null;
if (cursor != null) {
PlanList = new ArrayList<>();
if(cursor.moveToFirst()) {
do {
Object obj = getPlan(cursor);
PlanList.add((Plan) obj);
} while (cursor.moveToNext());
}
cursor.close();
}
return PlanList;
}
但没有效果。关于如何按月获得所有价值的任何想法?
答案 0 :(得分:4)
哦,好吧。
将您的查询更改为
SELECT * FROM workoutPlan WHERE strftime('%m', date) = '11'
或
SELECT * FROM workoutPlan WHERE CAST((strftime('%m', date)) AS INTEGER) = 11
就是这样。