按月份的Andr​​oid从数据库中获得的值 [英] Get values from database by month in android

查看:227
本文介绍了按月份的Andr​​oid从数据库中获得的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,在那里我有一个表:

I have a database where I have a table:

我想获得的所有值月11日 - 十一月。
我创建是这样的:

I want to get all the values for the month 11 - November. I created something like:

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;
    }

但是,没有效果。有关如何获得一个月的所有值的任何想法?

But no effect. Any idea about how get all values by month?

推荐答案

哦。

更改您的查询阅读

SELECT * FROM workoutPlan WHERE strftime('%m', date) = '11'

SELECT * FROM workoutPlan WHERE CAST((strftime('%m', date)) AS INTEGER) = 11

而这一切。

这篇关于按月份的Andr​​oid从数据库中获得的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆