tryingtolearn Posted December 7, 2009 Share Posted December 7, 2009 Hi all, can someone tell me if I am going about this the correct way (Or if there is a better way to do it) I need to get the difference between the time now and the timestamp of a MYSQL timestamp table. so it reads - 3 days 23 hours 14 minutes 32 seconds (For example) I think Its correct but for some reason it is really confusing me and just wondering if I should be doing it different. //current time $date1 = time(); //$exp is a mySQL timestamp field $date2 = strtotime($exp); $dateDiff = $date2 - $date1; $daysLeft = floor($dateDiff/(60*60*24)); $hoursLeft = floor(($dateDiff-($daysLeft*60*60*24))/(60*60)); $minutesLeft = floor(($dateDiff-($daysLeft*60*60*24)-($hoursLeft*60*60))/60); $secondsLeft = floor(($dateDiff-($daysLeft*60*60*24)-($hoursLeft*60*60)-($minutesLeft*60))); Quote Link to comment https://forums.phpfreaks.com/topic/184328-date-difference-am-i-doing-this-right/ Share on other sites More sharing options...
premiso Posted December 7, 2009 Share Posted December 7, 2009 If it works, it is probably correct. As for doing it different, it looks fine to me as long as it works. The date difference expressed out how you want it is rarely an easy task to accomplish. If you want to compare you code to other functions you can find plenty via google. Quote Link to comment https://forums.phpfreaks.com/topic/184328-date-difference-am-i-doing-this-right/#findComment-973134 Share on other sites More sharing options...
tryingtolearn Posted December 7, 2009 Author Share Posted December 7, 2009 Thanks - google was my friend with getting this hahaha Appreciate you taking a look. It just got confusing w/ all the math I guess... Quote Link to comment https://forums.phpfreaks.com/topic/184328-date-difference-am-i-doing-this-right/#findComment-973141 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.