Reputation: 173
I am trying to make a Java Thread, this thread have to delete from an MySQL database all the records, older than 7 days.
In my table i have a column that contain the date like this: 2013-10-28 17:00:00
.
And to do this i want to use JDBI library. and my question here if any one could give me and example of the query that i have to write.
I think it should look like this:
h.execute("Delete from MyTable where date >= (dt.now.dayofmonth() -7)
Upvotes: 0
Views: 1533
Reputation: 8635
h.execute("DELETE FROM MyTable WHERE NOW() >= ADDDATE(date, INTERVAL 7 DAY);");
Upvotes: 2
Reputation: 13465
Try this::
h.execute("Delete from MyTable where DATEDIFF(CURDATE(), dateCOLUMN)>7");
Upvotes: 1