Data cannot be retrieved by given a specific month

拟墨画扇 提交于 2019-12-24 12:04:05

问题


I wanted to retrieve data which month is belong to 12.

 public Cursor readData()
    {
        Cursor c=database.rawQuery(" SELECT _id, Date,Weather,Status, TimeIn_Info, TimeOut_Info FROM " + MyDatabaseHelper.TABLE_INFO +
                        " WHERE  strftime('%m',Date) = ? ",
                new String[]{12+""}, null);
        if (c != null) {
            c.moveToFirst();
        }
        return c;
    }

However, no data get displayed. I have make sure it has a data with a month 12.

MyDatabaseHelper for Table_Info

     public static final String TABLE_INFO="Information";
     public static final String Date="Date";
     public static final String Status="Status";
     public static final String TimeIn_Info="TimeIn_Info";
     public static final String TimeOut_Info="TimeOut_Info";
     public static final String Weather="Weather";
     public static final String Name="Name";

     public void onCreate(SQLiteDatabase db) {
            db.execSQL("create table " + TABLE_INFO + " ( " + ID + " INTEGER PRIMARY KEY ,Name TEXT,Weather TEXT, Date DATETIME, Status Text, TimeIn_Info DATE TIME, TimeOut_Info DATETIME)");
      }

I select the date by using date-time picker and the Date holds the date with the format 19-12-2015.

There are nothing wrong with my database because data get displayed when I change the condition to name.

Can someone helps me to figure out the problem ?


回答1:


you can try to change insert datetime to format: 2015-12-15 (%Y-%m-%d)



来源:https://stackoverflow.com/questions/34373159/data-cannot-be-retrieved-by-given-a-specific-month

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!