This function implements the difference between two unix timestamps and returns the days, hours, minutes, and seconds of the difference between the two timestamps, accurate to seconds. Both parameters are timestamps, although the code is very simple, but it is very practical. This function implements the difference between two unix timestamps and returns the days, hours, minutes, and seconds of the difference between the two timestamps, accurate to seconds. Both parameters are timestamps, although the code is very simple, but it is very practical.
Function timediff ($ begin_time, $ end_time) { If ($ begin_time <$ end_time ){ $ Starttime = $ begin_time; $ Endtime = $ end_time; } Else { $ Starttime = $ end_time; $ Endtime = $ begin_time; } $ Timediff = $ endtime-$ starttime; $ Days = intval ($ timediff/86400 ); $ Remain = $ timediff % 86400; $ Hours = intval ($ remain/3600 ); $ Remain = $ remain % 3600; $ Mins = intval ($ remain/60 ); $ Secs = $ remain % 60; $ Res = array ("day" => $ days, "hour" => $ hours, "min" => $ mins, "sec" => $ secs ); Return $ res; } |