amelio Posted January 16, 2011 Share Posted January 16, 2011 I copied and pasted the code below from php manual, http://www.php.net/manual/en/datetime.diff.php, I should have got the result of '2' as they did but I got the result of '6015'. I can't think why this would be. Any help appreciated. $datetime1 = new DateTime('2009-10-11'); $datetime2 = new DateTime('2009-10-13'); $interval = $datetime1->diff($datetime2); echo $interval->format('%R%a days'); Quote Link to comment https://forums.phpfreaks.com/topic/224610-wrong-result-from-datetimediff/ Share on other sites More sharing options...
denno020 Posted January 16, 2011 Share Posted January 16, 2011 Did you look at the comments for some of the workarounds for PHP versions less than 5.3? I actually have 5.3 installed on my WAMP set up, but I still get the same error that you're getting. It's very weird.. Let us know if any of the work arounds do the trick for you Denno Quote Link to comment https://forums.phpfreaks.com/topic/224610-wrong-result-from-datetimediff/#findComment-1160253 Share on other sites More sharing options...
amelio Posted January 16, 2011 Author Share Posted January 16, 2011 I'm on 5.3 as well, makes no sense. Quote Link to comment https://forums.phpfreaks.com/topic/224610-wrong-result-from-datetimediff/#findComment-1160254 Share on other sites More sharing options...
amelio Posted January 24, 2011 Author Share Posted January 24, 2011 I found a listing that gets the right answer... $date1 = new DateTime("2009-10-11"); $date2 = new DateTime("2009-10-13"); $interval = $date1->diff($date2); echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days "; I'm not sure how 'm' gives the months remaining after the years have been calculated and 'd' also knows the remainder of days after months have been accounted for but it works that's the main thing. I'm wondering if the original listing didn't work because I am on a windows machine. Quote Link to comment https://forums.phpfreaks.com/topic/224610-wrong-result-from-datetimediff/#findComment-1164210 Share on other sites More sharing options...
jcbones Posted January 24, 2011 Share Posted January 24, 2011 It seems they won't fix this bug, read for yourself. Bug 51184 Quote Link to comment https://forums.phpfreaks.com/topic/224610-wrong-result-from-datetimediff/#findComment-1164225 Share on other sites More sharing options...
amelio Posted January 24, 2011 Author Share Posted January 24, 2011 Thanks jcbones, that's cleared it up, how strange. Quote Link to comment https://forums.phpfreaks.com/topic/224610-wrong-result-from-datetimediff/#findComment-1164771 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.