Php calculates the difference between two timestamps by day, hour, minute, and second.
Php calculates the difference between two timestamps by day, hour, minute, and second.
/*** Calculate the difference between two timestamps by day, hour, and minute * @ param $ unixTime_1 start timestamp * @ param $ unixTime_2 end timestamp * @ return array */function timeDiff ($ unixTime_1, $ unixTime_2) {$ timediff = abs ($ unixTime_2-$ unixTime_1); // computing days $ days = intval ($ timediff/86400 ); // calculated hours $ remain = $ timediff % 86400; $ hours = intval ($ remain/3600); // calculates the number of minutes $ remain = $ remain % 3600; $ mins = intval ($ remain/60); // calculates the number of seconds $ secs = $ remain % 60; return ['day' => $ days, 'hour' => $ hours, 'Min' => $ mins, 'sec '=> $ secs];} // Array (// [day] => 1 // [hour] => 0 // [min] => 3 // [sec] => 31 //)
/*** Calculate the difference between the two timestamps by day, hour, and minute * @ param $ date1 start time * @ param $ date2 end time * @ return array */function diffDate ($ date1, $ date2) {$ datetime1 = new \ DateTime ($ date1); $ datetime2 = new \ DateTime ($ date2); $ interval = $ datetime1-> diff ($ datetime2 ); $ time ['Year'] = $ interval-> format ('% y'); $ time ['month'] = $ interval-> format (' % m '); $ time ['day'] = $ interval-> format ('% D'); $ time ['hour'] = $ interval-> format ('% H '); $ time ['Min'] = $ interval-> format ('% I'); $ time ['sec '] = $ interval-> format (' % s '); $ time ['days '] = $ interval-> format (' % A'); // returns $ time for the total days of two time differences ;} // Array (// [year] => 00 // [month] => 1 // [day] => 2 // [hour] => 00 // [min] => 3 // [sec] => 31 // [days] => 33 //)