pardom-zz / ActiveAndroid

Active record style SQLite persistence for Android
http://www.activeandroid.com
4.71k stars 1.03k forks source link

Select query #513

Open shyamkumarm opened 7 years ago

shyamkumarm commented 7 years ago

Hi guys I need to know

Sqllite query for select the record older than 30 days, Statement : String sql = "SELECT * FROM myTable WHERE myDate <= date('now','-30 day')"; Cursor mycursor = db.rawQuery(sql);

And what would be the query in active android i just tried below snippet List dataModel = new Select().from(DatabaseModel.class).where("timestamp <= date('now','-30 day')").execute(); Result : its selects all records, Anyone help me about, if you got any solution

uncledoc commented 7 years ago

Hi if field myDate as java.util.Date or java.sql.Date or Calendar use "SELECT * FROM myTable WHERE date(myDate/1000, 'unixepoch') <= date('now','-30 day')"; else if field myDate as String you need to specify date format via date function