在我的php文件中,我从mysql db中选择一个datetime字段。 我需要知道,这个值和now()
之间的差异,以秒(数值)表示e.g:
来自db的值:2014-02-02 16:58:22
现在是:2014-02-03 16:59:00
结果:86438
提前致谢
答案 0 :(得分:1)
试试这个http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampdiff
SELECT TIMESTAMPDIFF(SECOND, '2014-02-02 16:58:22', '2014-02-03 16:59:00')
答案 1 :(得分:0)
如果要在PHP中计算,可以使用DateTime
对象
$First = new DateTime('2014-02-02 16:58:22');
$Second = new DateTime('2014-02-03 16:59:00');
echo "The difference is " . ($Second->getTimestamp() - $First->getTimestamp()) . " seconds";
将输出:
The difference is 86438 seconds