Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve data between two dates in Android SQLite

Tags:

android

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

like image 928
Pooja Avatar asked May 08 '26 08:05

Pooja


1 Answers

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});        
}
like image 117
Hoan Nguyen Avatar answered May 10 '26 06:05

Hoan Nguyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!