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)); Link to comment https://forums.phpfreaks.com/topic/256985-days-left-to-include-leap-year/ 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? Link to comment https://forums.phpfreaks.com/topic/256985-days-left-to-include-leap-year/#findComment-1317420 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()); Link to comment https://forums.phpfreaks.com/topic/256985-days-left-to-include-leap-year/#findComment-1317424 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 Link to comment https://forums.phpfreaks.com/topic/256985-days-left-to-include-leap-year/#findComment-1317446 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.