1

I want to delete every row from the database where the Submission field is not in the future. The date is stored this way:

09/10/2013

So, in this example i want to delete this record, because its already expired. This is where i am:

$wpdb->query("DELETE FROM `$table_name` WHERE `Submission` < NOW()");

Looks fine for me, but this query deletes everything from the table, not just rows in the past.

Cœur
  • 37,241
  • 25
  • 195
  • 267
passatgt
  • 4,234
  • 4
  • 40
  • 54

1 Answers1

5

That date is not a valid datetime. It's a string. You need to use STR_TO_DATE() to convert it into a date before doing date math on it.

DELETE FROM `$table_name` WHERE STR_TO_DATE(`Submission`, '%m/%d/%Y') < NOW()
John Conde
  • 217,595
  • 99
  • 455
  • 496