android - How to pass yyyy-mm String to yyyy-mm-dd datetime string to filter records from sqlite? -
here have datetime string in yyyy-mm-dd format like
- 2016-08-26
- 2016-09-21
- 2015-07-23
- 2016-04-25
what need if pass 2016-08 in parameter need record of 2016-08-26 need how can achieve far have tried
public list<customermodel>date(string year){ string countquery ="select * "+customermodel.customertable + " " +customermodel.customer_createdat + " strftime('%y-%m',"+customermodel.customer_createdat+") = "+year +""; cursor cursor = db.rawquery(countquery, null); list<customermodel>list=new arraylist<>(); if(cursor!=null && cursor.getcount()>0){ if(cursor.movetofirst()){ do{ customermodel accountmodel=new customermodel(); accountmodel.setcreatedbyname(cursor.getstring(cursor.getcolumnindex(customermodel.customer_createdby))); // accountmodel.setcreatedat(cursor.getstring(1)); list.add(accountmodel); }while (cursor.movetonext()); } } if(cursor!=null){ cursor.setnotificationuri(mcontext.getcontentresolver(),db_timetracker ); } return list; }
am getting sqlite exception how achieve possible in advance.
try query
select * table_name created_date '2016-08%'
this give multiple records if have more 1 date particular year , month. replace date sting using string functions date field.
Comments
Post a Comment