I know, you better use DateTime()
, but no one here is talking about your issue and why are you getting the wrong result .
Its because date()
function get 2nd parameter as time stamp and returns the date : 1970-1-1 00:00:00 GMT
+ given time stamp
, pay attention to GMT part.
it means if your time zone is +2, then echo date("Y-m-d H:i:s",0)
returns 1970-1-1 2:00:00
, not 1970-1-1 00:00:00
.
So, the result that you are getting, is 07:02
(real different) + 2 hours
(your time zone) . if you insist of getting the result using date()
, you must change the last lines to:
$runing_time= $done_dt - $created_dt - 2*3600;
$runing_time= date('H:i',$runing_time);
//returns 07:02