【问题标题】:How to check time difference in mysql query?如何检查mysql查询中的时差?
【发布时间】:2022-11-04 16:05:14
【问题描述】:

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

$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.

【问题讨论】:

  • 如果它仅用于开发目的,则使用 laravel 调试栏(包)它显示与查询相关的信息,包括执行时间

标签: php mysql laravel


【解决方案1】:

尝试使用TIMEDIFF

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-14
    • 2020-12-18
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多