如何在mysql查询中检查时差



我正在使用laravel开发API,我在计算两个时间戳之间的时间差时遇到了问题。我的数据库位于另一个区域,我的机器运行在UTC计时,所以我无法找到两个时间戳之间的确切时间差,有什么方法可以检查查询级别本身的时间戳吗?我尝试过使用TIMESTAMPDIFF((,但它没有按预期工作

$childdata = $childConnection->query("select useractivitytime,idfrom userdetails where status = 0");
$current_date_time = Carbon::now()->format('Y-m-d h:i:s'); // this gives me the application running time.
$difference_in_seconds = strtotime($current_date_time) - strtotime($value['js_useractivity']); //result in seconds.

尝试使用TIMEDIFF:

select 
TIME_TO_SEC(TIMEDIFF(NOW(), useractivitytime)) AS difference_in_seconds, 
id 
from 
userdetails 
where 
status = 0

最新更新