检查日期是否晚于当前日期。

6

如何检查日期是否晚于当前日期?

if(date("d") < "18" && date("m") < "01") { 
    echo 'To late!';
}

对我来说无法运行。


1
如果你想检查当前日期是否在某个时间之后,为什么要使用小于符号呢? - Barmar
3个回答

7
您可以采用这种表示法:
if( '20140505' > date("Ymd") ) {
    // today's date is before 20140505 (May 5, 2014)
}

需要手动构建日期字符串,我认为这不是一个很好的主意。使用strtotime() - 或者更好的是,使用DateTime类。 - Amal Murali

5
$time1  = strtotime(date("d/m/Y", "18/01/2014"));
  if(time() > $time1)
   {
     echo "too late!";
   } 

0
最好使用strtotime。
$current_date = date("Y-m-d");
$date_to_compare = date("Y-m-d",time()+86400); //1 day later
if (strtotime($date_to_compare) > strtotime($current_date)) {
   echo "too late";
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接