conan318 Posted February 13, 2012 Share Posted February 13, 2012 the code was all working well but now new listings are displaying 28.958333333333 days left is this because its a leap year? $days = (strtotime(date("Y-m-d")) - strtotime($info['expiredate'])) / (60 * 60 * 24); $days=(abs($days)); Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 13, 2012 Share Posted February 13, 2012 Not likely. It's probably because of daylight savings time which changes on March 11 (at least for my location). Whenever calculating days you can avoid the problem by normalizing yoru date/times to noon (or some other time of day that won't be affected by DST). EDIT: The DST problem would only be an issue if 'expiredate' is in the future. Why are you doing the subtraction in reverse and then taking the absolute value? Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 13, 2012 Share Posted February 13, 2012 Forget what I said about normalizing the times to 12:00:00, that is a way to overcome a problem with DST, but a different problem than yours. You can simply round the result. function daysDiff($startDateTS, $endDateTS) { $days = round(($startDateTS - $endDateTS) / (60 * 60 * 24)); return $days; } $days = daysDiff(strtotime($info['expiredate']), time()); Quote Link to comment Share on other sites More sharing options...
conan318 Posted February 13, 2012 Author Share Posted February 13, 2012 thank you guys once again working perfectly now 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.