0

My timestamp format looks like this: 2014-02-27 08:54:53

The table is product_views, and the time field is ViewStamp. I don't know how to DELETE rows older than 7 days.

$query="DELETE FROM product_views WHERE ViewStamp< ?";

Thanks for the help. I am still a beginner so if I did not provide enough info please let me know and I will edit.

edit: Using MySQL

Mike
  • 105
  • 12

4 Answers4

1

DELETE FROM product_views WHERE ViewStamp < DATE_SUB(?, INTERVAL 7 DAYS)

If you just want from "now" instead of passing a timestamp as a parameter, you can replace the ? with the SQL function NOW().

Zebra North
  • 11,412
  • 7
  • 37
  • 49
1

Try like:

DELETE FROM product_views WHERE ViewStamp < (NOW() - INTERVAL 7 DAY)
aksu
  • 5,221
  • 5
  • 24
  • 39
0
$query = "DELETE FROM product_views WHERE ViewStamp < now() - interval 7 day";
thomas.mc.work
  • 6,404
  • 2
  • 26
  • 41
0

Using the date_add function you can do this. Assuming that you are using MySQL

DELETE FROM product_views WHERE ViewStamp < DATE_ADD(NOW(),INTERVAL -7 DAY)
Simon Blok
  • 66
  • 4