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 Link to comment https://forums.phpfreaks.com/topic/207480-time-difference/ 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); Link to comment https://forums.phpfreaks.com/topic/207480-time-difference/#findComment-1084737 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; } Link to comment https://forums.phpfreaks.com/topic/207480-time-difference/#findComment-1084745 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? Link to comment https://forums.phpfreaks.com/topic/207480-time-difference/#findComment-1084756 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 Link to comment https://forums.phpfreaks.com/topic/207480-time-difference/#findComment-1084765 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. Link to comment https://forums.phpfreaks.com/topic/207480-time-difference/#findComment-1084773 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. Link to comment https://forums.phpfreaks.com/topic/207480-time-difference/#findComment-1084785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.