Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将今天的日期与php中存储的日期进行比较_Php_Date - Fatal编程技术网

将今天的日期与php中存储的日期进行比较

将今天的日期与php中存储的日期进行比较,php,date,Php,Date,我试图使用PHP比较两个日期(一个存储在db中)和今天的日期,并根据比较结果输出“print”语句。我的到期日期在数据库中存储为“datetime”。它通过查询调用,并分配给变量$expire。下面是我用于比较的代码,但无论日期如何,它总是返回false <? $todays_date = date("m-d-Y"); $today = strtotime($todays_date); $expired = strtotime($expire); if ($tod

我试图使用PHP比较两个日期(一个存储在db中)和今天的日期,并根据比较结果输出“print”语句。我的到期日期在数据库中存储为“datetime”。它通过查询调用,并分配给变量$expire。下面是我用于比较的代码,但无论日期如何,它总是返回false

<? 
  $todays_date = date("m-d-Y"); 
  $today = strtotime($todays_date); 
  $expired = strtotime($expire); 

  if ($today > $expired) {
    print "<a target='_blank' href='/pdfwriter/generate_certificate.php?member=".$memberID."'>Print Membership Certificate</a>";
  } 
  else 
  {
    print "<a href='registration/registration.aspx?registerType=1'>Membership Expired - Renew Today</a>";
  } 
?>

使用
DateTime()
更容易做到这一点,因为它使比较日期更容易。不需要转换为时间戳或任何东西,而且它考虑了夏令时。我还认为你的比较运算符是反向的

$today = new DateTime();
$expires = new DateTime($expire);
if ($today < $expires)
{
    print "<a target='_blank' href='/pdfwriter/generate_certificate.php?member=".$memberID."'>Print Membership Certificate</a>";
}
else
{
    print "<a href='registration/registration.aspx?registerType=1'>Membership Expired - Renew Today</a>";
}
$today=new DateTime();
$expires=新日期时间($expire);
如果($今天<$到期)
{
打印“”;
}
其他的
{
打印“”;
}

strotime()
这样的函数在较新版本中已被弃用。不要使用它们。请具体说明question@Lion这是个好消息,但是您在哪里看到strotime()被弃用了呢?对不起,这也没用。我不是程序员,只是想编辑更多功能。在数据库中显示
$expire
的有效日期它看起来像这样:2013-08-06 00:00:00对我有效:。不知道怎么了。当我使用new DateTime()时,它会打断整个页面。谢谢你的努力。