PHP检查过去日期

PHP检查过去日期,php,Php,我正在使用RFC822日期格式,并试图使我的if语句工作,但它不会工作,我无法找出原因,这就是数据的回音: $currentdate = Fri, 01 Mar 13 22:24:02 +0000 $post['created_on'] = Sat, 17 Nov 2012 19:26:46 +0100 我的声明如下: $currentdate = date(DATE_RFC822, strtotime("-7 days")); if ($post['created_on'] < $cu

我正在使用RFC822日期格式,并试图使我的if语句工作,但它不会工作,我无法找出原因,这就是数据的回音:

$currentdate = Fri, 01 Mar 13 22:24:02 +0000
$post['created_on'] = Sat, 17 Nov 2012 19:26:46 +0100
我的声明如下:

$currentdate = date(DATE_RFC822, strtotime("-7 days"));
if ($post['created_on'] < $currentdate) 
{
  echo "test";
}
else
{

}
$currentdate=日期(日期\u RFC822,标准时间(“-7天”);
如果($post['created_on']<$currentdate)
{
回声“测试”;
}
其他的
{
}

我试图检查上创建的数组是否在过去7天内,我假设这与“有关,您的代码无法在进行字母数字比较时工作。RFC822不是为此而设计的

请注意,
Fri…
低于
Sat…
是这样的比较,如字母表中
F
位于
S
之前

使用该类:

$currentdate=new DateTime('-7days+0100');//!使用与post相同的tz偏移量!
$postdate=新的日期时间('Sat,2012年11月17日19:26:46+0100');
如果($postdate<$currentdate){
//…干什么
}

要比较时间戳:

<?php
if (strtotime($post['created_on']) >= strtotime('-7 days'))
{
    // Created in the last seven days
}

您正在比较字符串,而不是日期。这对夏令时不起作用。一年两次您会有bug。请使用DateTime
<?php
if (strtotime($post['created_on']) >= strtotime('-7 days'))
{
    // Created in the last seven days
}