0
我需要比较PHP中的日期,以检查合同是否已过期。在PHP中使用时间戳
现在我这样做:
foreach ($this->array as $row)
{
if(strtotime($date1) > strtotime($row['end_date']))
{
$delay = strtotime($row['end_date']);
$expired = "V";
}
else {
$delay = strtotime($row['end_date']);
$expired = "X";
}
所以我只知道,如果合同已经到期。我需要写:
echo "The contract will expire in" . $delay;
和输出是:
The contract will expire in 3 days.
感谢您的帮助。
已经回答:[如何比较PHP 5.2.8中的两个DateTime对象?](http://stackoverflow.com/questions/961074/how-do-i-compare-two-datetime-objects-in- php-5-2-8) – ThinkTank
我不明白这是如何解决我的问题的。 –
您需要将strtotime($ row ['end_date'])'与'time()'进行比较,你在他们之间的秒数,然后将其转换为日期 – Adam