get_date()'并通过SQL函数now()将时间存储在表中


How to get the different time between time from php function 'get_date()' and time stored in table by sql function now()?

使用php和MySQL,我想在php代码中获得get_date()函数获得的时间和NOW() sql函数存储在表中的时间之间的持续时间。如何做到这一点?请帮帮我。

这可能行得通:

$result = mysql_query("SELECT UNIX_TIMESTAMP() - " . time() . " AS diff");
$result = mysql_fetch_array($result);
$diff = $result['diff'];

$diff将包含mysql服务器和webserver之间的秒差

编辑:获取HH:MM:SS差异

$result = mysql_query("SELECT TIMEDIFF(UNIX_TIMESTAMP(), " . time() . ") AS diff");

Mysql日期将以'YYYY-MM-DD HH:II:SS'格式的字符串返回。使用strtotime($date_from_db)将其转换为PHP日期。如果要获取当前日期/时间,不要使用getdate()函数,而是使用now()函数。之后,使用相同的指令从链接PHP如何找到时间经过的日期时间?.