如何从php中的SQL时间日期格式中获取时间间隔


How to get time interval from SQL time date format in php

我从数据库中获得两个时间间隔,例如:

PickUpDateTime = "2013-4-20 12:00:00"和CCD_ 2。

如何在PHP中找到这两个时间之间的时间间隔?

将转换为秒,然后减去。

$date1 = strtotime($mysqldate1);
$date2 = strtotime($mysqldate2);
$diff_in_seconds = abs($date1 - $date2);

我认为你可以使用Mysql TIMESTAMPDIFF:

SELECT TIMESTAMPDIFF(SECOND, returndatetime, pickUpDateTime) as diffInSeconds FROM table

您可以使用strtotime将它们转换为时间戳。然后进行减法/除法运算。

我会使用TIMEDIFF()作为mysql函数

https://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_timediff