deleting android SQLite rows older than x days

Viewed 30873

I want to delete all rows in table MYTABLE which are older than x days. Column SAVE_DATE Long is the time when the row was inserted in table.

I tried this but apparently it deletes all my rows:

long daysInMiliSec = new Date().getTime() - X
            * (24L * 60L * 60L * 1000L);
return db.delete(MYTABLE , SAVE_DATE
            " <= ?", new String[] { "" + daysInMiliSec }

What is wrong?

4 Answers

Delete data older than 2 days when the timestamp or date field is stored in milliseconds or an epoch integer.

DELETE FROM update_log WHERE timestamp <= strftime('%s', datetime('now', '-2 day'));
Related