我想获得 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;
}
Run Code Online (Sandbox Code Playgroud)
但是没有效果。关于如何按月获取所有值的任何想法?
那好吧。
更改您的查询以阅读
SELECT * FROM workoutPlan WHERE strftime('%m', date) = '11'
Run Code Online (Sandbox Code Playgroud)
或者
SELECT * FROM workoutPlan WHERE CAST((strftime('%m', date)) AS INTEGER) = 11
Run Code Online (Sandbox Code Playgroud)
就这样。
| 归档时间: |
|
| 查看次数: |
1332 次 |
| 最近记录: |