在android中按月从数据库中获取值

edi*_*233 2 sqlite android

我有一个数据库,其中有一张表: 在此处输入图片说明

我想获得 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)

但是没有效果。关于如何按月获取所有值的任何想法?

Fan*_*mas 6

那好吧。

更改您的查询以阅读

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)

就这样。