0

Here is my exact code:

$date = date('l, F j'); 
$start = $row['date']; // equal to Monday, April 15
$interval = $row['interval']; // this is equal to 7 
$end = date('l, F j', strtotime($start ."+$interval days"));

 if ($end < $date) { 
     // do this 
 } else { 
     //yada yada yada
 }

I dont know if Im using the variable $interval wrong or if the date strtotime +7 days can not be used in this date format. I would like to keep the date format in this but if I must change then I guess I have to. The question is Can I use this date format and still add $interval amount of days? When the $end date is less than the $date it should do one part of the code and its not doing that part.

Any help would be great. Thanks.

4

1 回答 1

3

如果那是您的确切代码,那么date(l, F j)第一行是语法错误,并且此代码永远无法按原样运行。

您的问题是您将时间值转换为字符串,然后进行字符串比较。

例如

('December 1' < 'February 15')

将是 TRUE,因为DF. 您需要比较 strtotime() 产生的原始时间戳,这是一个简单的整数:

if (strtotime($start) < strtotime($end)) {
   start is less than end
}
于 2013-04-23T21:51:07.957 回答