cloudll Posted February 15, 2017 Share Posted February 15, 2017 Hello, I am comparing these 2 time stamps to see how much time has passed. They time passed is 66 seconds. When I format them back into h:m:s, it shows 1 hour, 1 minute and 6 seconds instead of just 1 minute and 6 seconds. I was just wondering why this was? Thanks $startStamp = 1487156507; $endStamp = 1487156573; $howLong = $endStamp - $startStamp; echo $howLong . "<br>"; echo(date("h:m:s",$howLong)) . "<br>"; Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 15, 2017 Share Posted February 15, 2017 The date() function operates on Unix timestamps. Passing 66 to it means 1970-1-1 00:00:66 UTC. How this is displayed depends on the time zone. If you want an interval like 66 seconds, you need to actually create an interval and format that. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 15, 2017 Share Posted February 15, 2017 try $startStamp = 1487156507; $endStamp = 1487156573; $dt1 = new DateTime("@$startStamp"); $dt2 = new DateTime("@$endStamp"); echo $dt1->diff($dt2)->format('%H:%I:%S').'<br>'; //--> 00:01:06 Quote Link to comment Share on other sites More sharing options...
cloudll Posted February 15, 2017 Author Share Posted February 15, 2017 Thank you both for the link and example Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.