Forum Moderators: coopster
I have a table that includes a column for "last application date", let's simply call it "date".
Now the problem is how to automatically delete rows where the information in the "date" column has gone old, let's say by -86400 (1 day).
Example: today's date is April 11th, which means that all rows with the info April 10th in the date column would get deleted.
Thankful for all help.
You can delete all dates earlier than the current date by using the < operator and the date function:
$today = date("Y-m-d");
mysql_query("DELETE FROM table WHERE date < '$today'") or die(mysql_error());
This will delete all dates older than today. If you want to delete only dates from the day before, you can also use strtotime()
$today = date("Y-m-d", strtotime("-1 day"));
mysql_query("DELETE FROM table WHERE date = '$today'") or die(mysql_error());
Hope that helps.
dc