开发者

php: today to 2010-05-08 21:04:06, how can i divide this time length by 30 days?

from the time length

2010-01-09 21:04开发者_开发知识库:06 **to** 2010-02-08 21:04:06

how can I get date + time at each 30 day interval ?

So I should get

2010-02-09 21:04:06
2010-03-09 21:04:06
2010-04-09 21:04:06
2010-05-08 21:04:06

So everyday, a script will check today's date to see if it matches one of above. If there's a match update all rows added before today.

$point1 = "2010-02-09 21:04:06"

if (date("Y-m-d h:m:s") >= $point1){

mysql_query('UPDATE table SET status='checked' WHERE lastadded < $point1');

}


Getting 30 days from today can be done quickly via strtotime().

$nextMonth = date("Y-m-d H:i:s" ,strtotime("+30 days"));

Unless you have good reason to use PHP, I would suggest using MySQL for this task as it won't rely on external logic for the query.


I would suggest letting MySQL do this for you with the following query:

UPDATE table SET status='checked'
WHERE lastadded < DATE_SUB(NOW(), INTERVAL 30 DAY);

In english this updates every row with that was "lastadded" more than 30 days ago.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜