无法按给定的特定月份检索数据
Data cannot be retrieved by given a specific month
我想检索属于 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;
}
但是,没有显示任何数据。我确定它有一个 12 月的数据。
MyDatabaseHelper 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)");
}
我 select 使用 date-time picker
的日期,日期保存格式为 19-12-2015
.
的日期
There are nothing wrong with my database because data get displayed
when I change the condition to name.
谁能帮我解决这个问题?
您可以尝试将插入日期时间更改为格式:2015-12-15 (%Y-%m-%d)
我想检索属于 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;
}
但是,没有显示任何数据。我确定它有一个 12 月的数据。
MyDatabaseHelper 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)");
}
我 select 使用 date-time picker
的日期,日期保存格式为 19-12-2015
.
There are nothing wrong with my database because data get displayed when I change the condition to name.
谁能帮我解决这个问题?
您可以尝试将插入日期时间更改为格式:2015-12-15 (%Y-%m-%d)