-1

I am trying to come up with a way to delete entries that are x days old. Right now, every new entry has a time stamp by doing the following in the row default:

Column name: created, Not Null and on the default section I have

CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

So I was wondering what Delete query i could use in my app.connection to delete entries that are 2 days old. It is a bit confusing because it provides seconds, as I initially thought I could just get the current data-2 and delete all entries older than that.

Thanks

Strawberry
  • 33,338
  • 13
  • 38
  • 57
Matthew
  • 101
  • 7
  • Well there are `86400` seconds in a day . "It provides seconds" probably means it's returning an Epoch. So two days ago would be `CURRENT_TIMESTAMP - (86400 * 2)` – Brettski Mar 07 '21 at 04:24
  • It's great when systems make up there own time integers: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_now – Brettski Mar 07 '21 at 04:29
  • Or just 172800. – Strawberry Mar 07 '21 at 08:42

1 Answers1

0

You could use MySQL's event scheduler to run delete queries and clear 2 days old records.

Check this post MySQL record that would subject to TTL