您应该只在比较日期之外创建一个日期。之后,您应该创建给定日期的时间戳Sun, 02 Jun 2013 22:05:00 GMT
,并且应该将其转换为仅包含日期的日期字符串。然后你从中创建另一个时间戳......
如果你知道我的意思......这应该工作:
<?php
// First create the date
$date = 'Sun, 02 Jun 2013 22:05:00 GMT';
// To a timestamp
$t_date = strtotime($date);
// Noew remove the seconds: First create a new date, with a timestamp of the give date.
// After that create a datestring with only the date
$date = date("jS F Y", $t_date);
// And create a new timestamp
$t_date = strtotime($date);
// One week back: time - 60 seconds * 60 minutes * 24 hours * 7 days * -1 to get backwards
// And we only create a date of this
$weekback = date('jS F Y', time() + (60 * 60 * 24 * -7) );
// Create a timestamp
$t_weekback = strtotime($weekback);
// Debug
echo "Date: $date<br/>Date (UTC): $t_date<br/>";
echo "Last week: $weekback<br/>Last week (UTC): $t_weekback<br/>";
if ($t_date <= $t_weekback) {
//Date is older then a week
echo "Outside a week: last week($t_date) <= The date($t_weekback)";
}else{
//Date is within a week
echo "Within a week: $t_date > $t_weekback";
}
?>