Reputation: 17429
In my android application I perform some insert in a table which has a datetime column. For creating the data to inserd in that column I use the following code:
Date d = new Date((new Date()).getTime()+60000);
String exDate= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.ITALY).format(d);
and I have added this String in a DATETIME column (named timestamp) of my table.
Now I want perform a query in that table, which deletes all the rows in which the date in the timestamp column is greater then a givend Date. Something like this:
DELETE FROM mytable WHERE timestamp > mydate
I was trying to use the delete(String table, String whereClause, String[] whereArgs)
method inside the SQLiteDatabase
library.
Someone can help me?
Upvotes: 0
Views: 279
Reputation: 39846
in my experience, using a String as a date-time field is a bad choice. Use a long
instead. Android can create/set Date
or Calendar
objects based on the Unix Epoch and comparing a long
in the sqlLite is a breeze.
So yeah, my answer is: change the SQL create statement to use a INTEGER instead of TEXT and you can easilt call the delete statement you're trying to do.
Upvotes: 1