MasterACE14 Posted July 12, 2010 Share Posted July 12, 2010 if I have the following... $time1 = $row['time']; // 1278919417 $time2 = time(); how can I workout the time difference of the two variables? Regards, Ace Quote Link to comment Share on other sites More sharing options...
bh Posted July 12, 2010 Share Posted July 12, 2010 Hi, Theres a lots of same topic as yours in 'PHP Coding Help', look around. ---- unix timestamp - unix timestamp $time = $time2 - $time1; echo date('Y-m-d', $time); Quote Link to comment Share on other sites More sharing options...
myrddinwylt Posted July 12, 2010 Share Posted July 12, 2010 if($time2 > $time1) $diff = $time2 - $time1; } else { $diff = $time1 - $time2; } Quote Link to comment Share on other sites More sharing options...
salathe Posted July 12, 2010 Share Posted July 12, 2010 $diff = abs($time1 - $time2); Do you want the time difference in seconds, or some other format? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 12, 2010 Author Share Posted July 12, 2010 $diff = abs($time1 - $time2); Do you want the time difference in seconds, or some other format? in minutes please Quote Link to comment Share on other sites More sharing options...
myrddinwylt Posted July 12, 2010 Share Posted July 12, 2010 <?php function getTimeDiff($time1, $time2) { if($time2 > $time1) $diff = abs($time2 - $time1); } else { $diff = abs($time1 - $time2); } return CEIL($diff / 60); } ?> This should sum it up for you. Quote Link to comment Share on other sites More sharing options...
salathe Posted July 12, 2010 Share Posted July 12, 2010 No need for the if/else if you're using abs. 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.