I want to retrieve data between two dates in Android SQLite I used one function in SQLiteAdapter class. My function is
public void history(String startdate,String enddate) {
Cursor mCursor = db.rawQuery("SELECT * FROM "+ KK_AIRLINEBOOK +
" WHERE " + KEY_Bookingdate +
" BETWEEN " + startdate + " AND " + enddate , null);
}
However it doesn't work it shows syntax error near AND
Put literals
public void history(String startdate,String enddate) {
Cursor mCursor = db.rawQuery("SELECT * FROM "+ KK_AIRLINEBOOK +
" WHERE " + KEY_Bookingdate +
" BETWEEN '" + startdate + "' AND '" + enddate + "'", null);
}
However it is better if you use selectionArgs
public void history(String startdate,String enddate) {
Cursor mCursor = db.rawQuery("SELECT * FROM "+ KK_AIRLINEBOOK +
" WHERE " + KEY_Bookingdate +
" BETWEEN ? AND ?", new String[]{startdate, enddate});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With