tags:

views:

32

answers:

2

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');

}
+2  A: 

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.

Jonathan Sampson
+1  A: 

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.

hobodave