calculate the difference between 2 timestamps in php

前端 未结 5 943
时光说笑
时光说笑 2020-12-05 19:06

I am using 2 timestamp in my table which is starttime datatype- timestamp and as current timestamp. endtime datatype-timestamp and default as 0000-00-00 00:00:00

ho

5条回答
  •  渐次进展
    2020-12-05 19:19

    You can convert your timestamps to unix timestamp (time in seconds) using php strtotime and then take the difference. You now have the difference in time in seconds and can convert to what you need...hours, min, days

    http://php.net/manual/en/function.strtotime.php

    ex:

    $ts1 = strtotime($start);
    $ts2 = strtotime($end);     
    $seconds_diff = $ts2 - $ts1;                            
    $time = ($seconds_diff/3600);
    

提交回复
热议问题