Reputation: 47
So i have a input called month, and i wanted to make a query so that from all the rows in a custom listview, the rows containing that specific month is returned. This is my code in my DBAdpater. What must i do so that the db returns all the rows that contain that specific month. The format that my date is saved is 05/06/15. The string sent in the params is "/08/".
public Cursor getRowsFromMonth(String month){
String[] FROM = {
KEY_ROWID,KEY_DATE, KEY_DESCRIPTION, KEY_CATEGORY, KEY_AMOUNT, KEY_PAIDBY
};
String where = "date=?";
String[] whereArgs = new String[] {
"%"+ month+"%"
};
return db.query(DATABASE_TABLE, FROM, where, whereArgs, null, null, null);
}
Upvotes: 0
Views: 57
Reputation: 75629
If you are using wildcard character (%
) then your where clause should use LIKE
not =
, instead of
String where = "date=?";
you need
String where = "date LIKE ?";
But, I'd also rethink how your date is stored as you may want to use sqlite's date time functions some day:
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC. Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
https://www.sqlite.org/datatype3.html
Upvotes: 1