简体   繁体   中英

Sqlite delete rows older than

I have records in database:

record B with property `Checked` set to be current date in UTC.
record A with property `Checked` set to be current date in UTC - 48 hours.

Then I want to create query to delete rows with property Checked older than 24 hours.

In my case only A should be deleted. Checked is stored as bigint in database.

db.Execute("DELETE FROM User WHERE Checked <= strftime('%s', datetime('now', '-1 day'))"); // A and B are not deleted
db.Execute("DELETE FROM User WHERE Checked <= datetime('now', '-1 day')"); // A and B are deleted
db.Execute("DELETE FROM User WHERE Date(checked) <= datetime('now', '-1 day')"); // A and B are not deleted
db.Execute("DELETE FROM User WHERE datetime(checked) <= datetime('now', '-1 day')"); // A and B are not deleted

Do you have any ideas what can be wrong there?

我终于找到了解决方案:

datetime(Checked/10000000 - 62135596800, 'unixepoch') <= datetime('now', '-1 day')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM