neeko
neeko

Reputation: 2000

Delete mysql row where date equals expiry date

What's the best way to run a mysql query to delete a row if it equals the date in the expire column?

This is my current code:

$sql = "DELETE * FROM table WHERE DATE(expire) = CURDATE()";

$q   = $conn->prepare($sql) or die("failed!");
// Bind the params to the placeholders
$q->execute();

Upvotes: 0

Views: 2955

Answers (2)

NeverendeR
NeverendeR

Reputation: 47

DELETE FROM TABLE WHERE expire < curDate()

Make sure you named the correct table and the correct fields..

Upvotes: 0

Adam Plocher
Adam Plocher

Reputation: 14233

Would this work?

DELETE FROM TABLE WHERE expire < CURRENT_TIMESTAMP

EDIT: As Greg said, I don't really see anything wrong with your current code. The code I provided might be a little more of a guarantee that your table is properly cleaned up.

Upvotes: 3

Related Questions