与存储的日期时间

时间:2016-04-05 22:29:20

标签: php mysql datetime

我正在尝试比较这两个DateTimes。 我将一个存储在数据库中,只要插入新行就存储该数据库。 另一个是当前的DateTime,但我正在尝试添加两分钟,然后进行比较。

我目前的代码:

$time = $cached_data["last_update"];
$date = new DateTime ('now');
$datef = $date->format('Y-m-d H:i:s');

// Check if the cached data has expired and if it has then update the data
if($datef > ($time)) {

    echo "updated";
}

同时响应$ datef和$ time给出:

$datef: 2016-04-06 00:23:43

$time: 2016-04-05 18:21:03

并且脚本回显“已更新”。

我意识到我的系统上的时间和数据库的时间不同,但我如何将这两分钟添加到$datef并且这会有效吗?

0 个答案:

没有答案