PHP - 检查时间是否已过去

时间:2013-10-31 01:02:41

标签: php if-statement time

$from = time();
$to = strtotime($row['clock']);
if($to<$from){
    echo("Time has past.");
}

我只是想用一个简单的IF语句检查时间是否过去了。

目前if语句始终为true,无论日期时间如何。

$ row ['clock'] = 2013-10-31 00:04:00

1 个答案:

答案 0 :(得分:3)

这在这里工作正常。确保$row['clock']包含您认为的内容。

$from = time();
$to = strtotime('2013-11-01 00:00:00');
if($to<$from){
    echo("Time has past.");
}

在我的机器上没有任何回声,而:

$from = time();
$to = strtotime('2013-10-01 00:00:00');
if($to<$from){
    echo("Time has past.");
}
回声“时间过去了。”。

除此之外,请检查服务器的时间是否正确设置。