android - SQLite Query not working when dates are compared in where clause -


i want fetch records between 2 dates sqlite table, doesn't work when dates compared in clause, works other string column used condition or when no clause specified, there other way use dates in clause.

cursor = db.rawquery("select min(activity_date), max(activity_date) tbl_activity_details" , null); if(cursor != null) {     itemslist.clear();     while(cursor.movetonext()) {         itemslist.add(cursor.getstring(0));         itemslist.add(cursor.getstring(1));     }     cursor.close();     try {         fromdate = sdf.parse(itemslist.get(0));         todate = sdf.parse(itemslist.get(1));     } catch(exception e) {         e.printstacktrace();     }      try {         toast.maketext(this, "here "+sdf.format(fromdate)+"  "+sdf.format(todate), 5000).show();         //toasts 2015-04-23 2015-05-01         string fd = sdf.format(fromdate);         string td = sdf.format(todate);          cursor1 = db.rawquery("select * tbl_activity_details activity_date between '"+fd+"' , '"+td+"'", null);          toast.maketext(this, "here 1"+cursor1.getcount(), 5000).show();         //toasts here 1 10         if(cursor1 != null) {             while(cursor1.movetonext()) {                 toast.maketext(this, "here 2"+cursor1.getstring(0), 5000).show();             }          } else {             toast.maketext(this, "no record found", 5000).show();         }         cursor1.close();     } catch (exception e) {         e.printstacktrace();     } {         db.close();     } 

i've asked similar question , answer might out, here's question.

a quick snippet answer relevant you:

if you're use string data type in sqlite, have format system.currenttimemillis() date format "yyyy/mm/dd". if use other formats such m/d/yyyy --> have date string comparing issues. see issue below m/d/yyyy format:

"5/15/2015".compareto("11/30/2015") ---> return 4 > 0 --> means "5/15/2015" > "11/30/2015" --- wrong 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -