Home > Mobile >  How to check time difference in mysql query?
How to check time difference in mysql query?

Time:11-04

I am using laravel to develop API, i was stuck at one point calculating time difference between two time stamps .my database is present in another region and my machine running on UTC timing so i could not able to find exact time difference between two time stamps ,is there any way to check timestamp in the query level itself i have tried with TIMESTAMPDIFF() but it's not working as expected

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

CodePudding user response:

Try using TIMEDIFF:

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