android - Select some data from SQLite using a date filter? -


i want select data database table using filter date (date column is: [searchdate] datetime default current_timestamp,)

in pic, i'm using sqlite expert , filter date: enter image description here

and code getting current year , month:

dateformat year_format = new simpledateformat("yyyy");         dateformat month_format = new simpledateformat("mm");         year_date = year_format.format(new date());         month_date = month_format.format(new date());         date date = new date();         log.d("month", year_format.format(date) + " " + month_format.format(date)); 

and cursor query in app getting list filtered date (current year):

public list<moment> moment_year(string year) {         try {             moment moment_table;             list<moment> moments = new arraylist<>();             db_helper.opendatabase();             db.begintransaction();             cursor moment_cursor = db.rawquery("select * tblmoment strftime('%y', searchdate) =" + year, null);             db.settransactionsuccessful();             moment_cursor.movetofirst();             while (!moment_cursor.isafterlast()) {                 moment_table = new moment(moment_cursor.getint(0), moment_cursor.getstring(1), moment_cursor.getstring(2), moment_cursor.getstring(3),                         moment_cursor.getstring(4), moment_cursor.getstring(5), moment_cursor.getint(6), moment_cursor.getint(7) != 0);                 moments.add(moment_table);                 moment_cursor.movetonext();             }             moment_cursor.close();             return moments;         } catch (exception e) {             return null;         } {             db.endtransaction();             db_helper.closedatabase();         }     } 

i tried, nothing happens , list null (empty).
have dates in current year.

isn't clear? surround year variable sql string delimiters (') in query.

cursor moment_cursor =      db.rawquery("select * tblmoment strftime('%y', searchdate) = '" + year + "'", null); 

or use parametric query (the string delimiters handled android).

cursor moment_cursor =      db.rawquery("select * tblmoment strftime('%y', searchdate) = ?", new string[]{year}); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -