calculate the difference between 2 timestamps in php

前端 未结 5 933
时光说笑
时光说笑 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

    try this code, tested on phpfiddle.org :-

    function timestampdiff($qw,$saw)
    {
        $datetime1 = new DateTime("@$qw");
        $datetime2 = new DateTime("@$saw");
        $interval = $datetime1->diff($datetime2);
        return $interval->format('%Hh %Im');
    }
    echo timestampdiff('1524794340', '1524803100');
    

提交回复
热议问题