DROP TABLE IF EXISTS `t`; CREATE TABLE `t` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ts` timestamp , PRIMARY KEY (`id`) ) ; INSERT INTO `t` VALUES ('1', '2014-01-06 17:01:36');
-- DELETE FROM t WHERE ts < UNIX_TIMESTAMP(CONCAT(DATE_SUB(DATE(NOW()),INTERVAL -3 MONTH ),' ',CURTIME())) SELECT ts, UNIX_TIMESTAMP(ts) < UNIX_TIMESTAMP ( CONCAT( DATE_SUB(DATE(NOW()), INTERVAL 3 MONTH), ' ', CURTIME() ) ), ( CONCAT( DATE_SUB( DATE(NOW()), INTERVAL 3 MONTH ), ' ', CURTIME() ) ), UNIX_TIMESTAMP(ts) < UNIX_TIMESTAMP ( CONCAT( DATE_SUB(DATE(NOW()), INTERVAL 1 MONTH), ' ', CURTIME() ) ), ( CONCAT( DATE_SUB( DATE(NOW()), INTERVAL 1 MONTH ), ' ', CURTIME() ) ) FROM t
php 相关代码
date('Y-m-d H:i:s', strtotime('-3 month'));