PHP Mysql:查找表格中的过期日期并将其延长
嗨-我有一个php分类广告网站,我是否可以运行一个命令来查找过期的广告,并自动将日期增加XX天。
这是一个结构
DATEBASE = "realestatedb"
table names are
"tt_44" to "tt_56" 字段名为ExpireDate类型为date
我读过..PHP Select from MySQL where date field is 7 days in the future
但还是想不通
这样行得通吗
SELECT *
FROM realestatedb
WHERE status IN('','ExpireDate')
AND expiry_date = DATE(NOW() + INTERVAL 7 DAY)发布于 2015-01-07 01:29:39
添加到日期的MySQL函数是DATE_ADD。您可以使用DATE_ADD(字段名,间隔7天)将7天添加到字段中。
您想要在过期日期中添加一些天数。所谓过期,我假设你的意思是它们是在某个日期之前。因此,假设过期意味着在2015-01-01之前。然后,您将使用:
UPDATE tt_44 SET ExpireDate = DATE_ADD(ExpireDate, INTERVAL 7 DAY) where ExpireDate<'2015-01-01';这将使表tt_44中2015-01-01之前的每个日期增加7天
发布于 2015-01-07 02:00:56
我不得不运行命令几次,这样它就会更新所有的命令,你知道为什么吗?
mysql> UPDATE tt_44 SET ExpireDate = DATE_ADD(ExpireDate, INTERVAL 365 DAY) where ExpireDate<'2015-01-01';
Query OK, 72 rows affected (0.01 sec)
Rows matched: 72 Changed: 72 Warnings: 0
mysql> UPDATE tt_44 SET ExpireDate = DATE_ADD(ExpireDate, INTERVAL 365 DAY) where ExpireDate<'2015-01-01';
Query OK, 15 rows affected (0.00 sec)
Rows matched: 15 Changed: 15 Warnings: 0
mysql> UPDATE tt_44 SET ExpireDate = DATE_ADD(ExpireDate, INTERVAL 365 DAY) where ExpireDate<'2015-01-01';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> UPDATE tt_44 SET ExpireDate = DATE_ADD(ExpireDate, INTERVAL 365 DAY) where ExpireDate<'2015-01-01';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> UPDATE tt_44 SET ExpireDate = DATE_ADD(ExpireDate, INTERVAL 365 DAY) where ExpireDate<'2015-01-01';
Query OK, 0 rows affected (0.01 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> UPDATE tt_44 SET ExpireDate = DATE_ADD(ExpireDate, INTERVAL 365 DAY) where ExpireDate<'2015-01-01';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0https://stackoverflow.com/questions/27803887
复制相似问题