Seaholme Posted July 20, 2010 Share Posted July 20, 2010 Hey, I'm trying to work out how long it is between the present time and a previous time which I am retrieving from my database. Both of the dates are in the same format, but no matter what I do the difference comes out as the number 8! Can anybody help me fix this up? All of the variables (the lastclick and the currentdate ones) are working when I echo them, sooo.... // Find highest answer number. $sql = "SELECT * FROM players"; $result2=mysql_query($sql) or die(mysql_error()); while ($rows=mysql_fetch_array($result2)){ echo $rows['lastclick']; } $currentdate=date("G:i:s d/m/y"); $difference = $currentdate - $rows['lastclick']; echo $difference; Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/208310-finding-the-difference-between-two-times/ Share on other sites More sharing options...
gwolgamott Posted July 20, 2010 Share Posted July 20, 2010 Convert the times into unix time stamps then subtract the results of those. Then convert that difference to whatever you want. See: mktime() http://us2.php.net/manual/en/function.mktime.php Quote Link to comment https://forums.phpfreaks.com/topic/208310-finding-the-difference-between-two-times/#findComment-1088681 Share on other sites More sharing options...
AbraCadaver Posted July 20, 2010 Share Posted July 20, 2010 I like strtotime(): $difference = time() - strtotime($rows['lastclick']); // difference in seconds You could also retrieve it from the database with UNIX_TIMESTAMP() and you wouldn't need the strtotime(). Quote Link to comment https://forums.phpfreaks.com/topic/208310-finding-the-difference-between-two-times/#findComment-1088702 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.