PHP日期时间函数:使内容过期

PHP日期时间函数:使内容过期,php,Php,如何使内容从添加日期起两天后过期。 从mysql获取数据后 //looop starts { $db_Date = $rows['created_Date']; //output 2014-01-10 12:08:56 /* Now i have to expire the content after 2 days from the added date and time i.e i want to expire by 2014-03-10 12:08:

如何使内容从添加日期起两天后过期。 从mysql获取数据后

    //looop starts
    {
       $db_Date = $rows['created_Date']; //output 2014-01-10 12:08:56
      /* Now i have to expire the content after 2 days from the added date and time i.e i want to expire by 2014-03-10 12:08:56*/
//    I tried like this
        $date = new DateTime($rows['created_Date'];);
        $now = new DateTime();  

        if($date < $now) {
            echo 'date is in the past';
        } // this is not working as 

       <div>My Content</div>
    }
您可以使用:

或者您可以使用:

或者,要完成此答案并考虑H2Oooo的答案,您可以直接在SQL中完成:

SELECT data FROM table WHERE id = 123 AND date >= DATE_SUB(NOW(), INTERVAL 2 DAY)
你可以用这个方法


改为从查询中执行:从表中选择数据,其中id=123,date>=date\u子行,间隔2天。
$date = new DateTime($rows['created_Date']);
$date->modify('+2 days');
SELECT data FROM table WHERE id = 123 AND date >= DATE_SUB(NOW(), INTERVAL 2 DAY)
 {
       $db_Date = $rows['created_Date']; //output 2014-01-10 12:08:56
      /* Now i have to expire the content after 2 days from the added date and time i.e i want to expire by 2014-03-10 12:08:56*/
//    I tried like this
        $date = new DateTime($rows['created_Date']);
        $date = $date->modify('+2 days');

        $now = new DateTime();  

        if($date < $now) {
            echo 'date is in the past';
        } // this is not working as 

       <div>My Content</div>
    }