Hey I have a table that every row contains several data and one of them is the date , I am trying to write a code in php that will run on the table and delete every row that its date have been expired for example if the date today is 06/01/2017 than every item that its date is smaller than today should be deleted, the thing is I don't really have an idea on how to write this function so if someone can send me a tutorial or example of how should I do it that will be great.
Asked
Active
Viewed 1,166 times
3 Answers
0
DELETE FROM your_table WHERE your_date_column < NOW()
for what concerns the SQL query... Then simply use PDO to execute it
Your question actually is quite general, sounds like homework... Otherwise, posting some code attempts is appreciated as much as showing you did try / make some research beforehand. :)

Shirraz
- 172
- 1
- 4
- 10
0
You'll need to create a page that sets tomorrow's date and executes the mysql command:
$conn = new mysqli($db_servername, $db_username, $db_password, $db_dbname);
if ($conn->connect_error) { }
$tomorrow = new DateTime('tomorrow');
$tomorrow->format('Y-m-d');
$sql = "DELETE FROM 'yourtable' WHERE Date < '{$tomorrow}'";
$result = $conn->query($sql);

Jack of Spades
- 94
- 3
0
you can use this query for delete past records
mysql> delete from your_table where date < curdate();

denny
- 2,084
- 2
- 15
- 19