0

Problem:

If the stored date ($stored_date) (yyyy-mm-dd) is greater than some time (2 months) then do something...

Code I Have Tried:

if(strtotime($stored_date) + strtotime('+2 month') <= strtotime('now')) {
   // Do something...
} else {
   // Do something...
}

However, this is not working for me. Any help would be appreciated. Thanks.

4

3 回答 3

4
if (strtotime($stored_date, '+2 month') > time())
于 2013-05-03T01:43:55.140 回答
4
$date = new DateTime($stored_date);
$date->add(new DateInterval('P2M'));
$now = new DateTime();
if ($date > $now)
{

}
于 2013-05-03T01:44:22.417 回答
1

只是为了另一种方法

//db stuff
$q=" SELECT * , IF( `dateField` + INTERVAL 2
MONTH > NOW( ) , 'yes', 'no' ) AS DATE_CHECK
FROM FOO";

//run query get data stuff

if($DATE_CHECK =='yes') {
   // Do something...
} else {
   // Do something...
}
于 2013-05-03T02:00:37.847 回答