我有这个查询,但我想根据服务器时间(或者如果服务器时间不可能按发布日期)更改日期以删除超过1小时前的所有内容。我该怎么做?
DELETE FROM wp_posts
WHERE post_date < '2008-06-06 19:18:00'
AND post_status = 'publish'
答案 0 :(得分:78)
使用:
DELETE FROM wp_posts
WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 HOUR)
AND post_status = 'publish'
参考:
答案 1 :(得分:30)
甚至更简单:
SELECT NOW() - INTERVAL 1 HOUR;
所以查询变为:
DELETE FROM wp_posts
WHERE post_date < NOW() - INTERVAL 1 HOUR
AND post_status = 'publish'
答案 2 :(得分:0)
Subdate函数也可以使用!
github_importer