php在发布后x天内显示链接

php在发布后x天内显示链接,php,dateinterval,Php,Dateinterval,我想在用户在网站上发布帖子后的X天内添加一个链接“续订帖子”,这将重新安排帖子到顶部(当然,基于从数据库检索的日期)。 我的数据库日期行上的时间戳格式为2014-02-12 15:06:44 $date = date('y-M-d l H:i a', strtotime($row['date'])); $days = 30; //what to put here? if ($date > $days){ echo '<a href="$click

我想在用户在网站上发布帖子后的X天内添加一个链接“续订帖子”,这将重新安排帖子到顶部(当然,基于从数据库检索的日期)。 我的数据库日期行上的时间戳格式为2014-02-12 15:06:44

    $date = date('y-M-d l H:i a', strtotime($row['date']));
    $days = 30; //what to put here?
    if ($date > $days){
       echo '<a href="$clicked">link here</a>';

       if ($clicked === true){
          mysql_query("UPADTE `posts` SET `date` = now()");
       }
    }
$date=date('y-M-dlh:ia',strottime($row['date']);
$days=30//在这里放什么?
如果($日期>$天){
回声';
如果($clicked==true){
mysql_查询(“UPADTE`posts`SET`date`=now()”;
}
}
链接应该允许他们更新时间戳,我知道我做错了,因为我不知道如何调用链接

我不确定应该将$days设置为什么。。感谢您的帮助

使用

或者在一个漂亮,整洁的一行

$days = 30;
if ((new DateTime($row['date']))->diff(new DateTime())->days > $days) {
    // etc
}
三十天前=时间()-24*60*60*30;

如果(strotime($row['date'])有另一种方法可以使用php计算当前日期30天之前的日期。我们可以在此处使用日、月和年。对于未来的日期计算,它将是+

$currentday = "2014-02-28";
$postdate = date($currentday,strtotime("-30 day")); //date before 30 days
$postdate = date($currentday,strtotime("+1 day")); //date after one day
$postdate = date($currentday,strtotime("+1 week")); //date after one week

当心DST的变化有点奇怪,一旦我把它上传到我的主机上,它就会告诉我“语法错误,意外的T_对象_运算符”但是在localhost上它是有效的。我如何定义dateinterval?@Bamba在PHP版本中听起来有点不同。试试上面更详细的代码片段。你的主机是什么版本的?5.2.x,我使用免费的主机服务查看它在我的手机和所有设备上的运行情况(localhost仅限于我的pc)但是,是的,我想这就是问题所在。必须要有一个更好的主机。5.2甚至不再受支持。如果你的手机和你的本地服务器(通过wifi)在同一个网络上,你应该能够通过它的IP访问它
$thirty_days_ago = time()-24*60*60*30;
if (strtotime($row['date'])<$thirty_days_ago){
$currentday = "2014-02-28";
$postdate = date($currentday,strtotime("-30 day")); //date before 30 days
$postdate = date($currentday,strtotime("+1 day")); //date after one day
$postdate = date($currentday,strtotime("+1 week")); //date after one week