Bug #65003 [Com]: Wrong date diff

From: Date: Mon, 11 Aug 2014 12:03:42 +0000
Subject: Bug #65003 [Com]: Wrong date diff
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187072@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65003&edit=1 ID: 65003 Comment by: ppasindud at gmail dot com Reported by: hcy321+php at yandex dot com Summary: Wrong date diff Status: Open Type: Bug Package: Date/time related Operating System: OSX PHP Version: 5.4.16 Block user comment: N Private report: N New Comment: Hi I had a similar error and check the src in intervel.c timelib_diff the date is changed to local or gmt from 13-03-01 13-04-01 to 13-02-28 13-03-31 rt->d = two->d - one->d; and makes it 1 month and 3 days could it be solved by only running timelib_apply_localtime if date zones are different or else can put some other conditions to to prevent this, any other way to solve this, bug is for php 5.4 but exists in newer versions too. Thanks Previous Comments: ------------------------------------------------------------------------ [2013-06-10 12:08:08] hcy321+php at yandex dot com Description: ------------ DateTime::diff return wrong result for first day of month. Tested on PHP Version 5.4.10 \ 5.4.15 Test script: --------------- <?php date_default_timezone_set('Europe/Moscow'); $datetime1 = new DateTime('13-03-01'); $datetime2 = new DateTime('13-04-01'); $datetime3 = new DateTime('13-03-02'); $datetime4 = new DateTime('13-04-02'); $interval = $datetime2->diff($datetime1); echo $interval->format('%m month, %d days'), '<br>'; //1 month, 3 days $interval = $datetime4->diff($datetime3); echo $interval->format('%m month, %d days'); //1 month, 0 days Expected result: ---------------- 1 month, 0 days 1 month, 0 days Actual result: -------------- 1 month, 3 days 1 month, 0 days ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65003&edit=1

« previous php.bugs (#187072) next »