简体   繁体   English

从mysql表中删除日期字段不在将来的每条记录

[英]Delete every record from mysql table where the date field is NOT in the future

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 2013/09/10

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. 对我来说看起来不错,但是此查询会删除表中的所有内容,而不仅仅是过去的行。

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. 在对日期进行数学运算之前,您需要使用STR_TO_DATE()将其转换为日期。

DELETE FROM `$table_name` WHERE STR_TO_DATE(`Submission`, '%m/%d/%Y') < NOW()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM