Re: Strange Result of Datetime::diff
| From: | Christoph M. Becker | Date: | Mon, 03 Apr 2017 15:44:57 +0000 |
| Subject: | Re: Strange Result of Datetime::diff | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-326043@lists.php.net to get a copy of this message | ||
On 03.04.2017 at 15:28, Aziz Saleh wrote:
> On Mon, Apr 3, 2017 at 8:39 AM, <naitsirch@e.mail.de> wrote:
>
>> I'd expect the following script:
>>
>> <?php
>>
>> $date1 = new DateTime('2017-03-01');
>> $date2 = new DateTime('2017-04-02');
>>
>> $diff = $date1->diff($date2);
>>
>> echo "{$diff->m} months and {$diff->d} days.";
>> ?>
>>
>> would print "1 months and 0 days.". But instead it prints "1 months and 3
>> days." (see https://3v4l.org/RMuUZ).
>> What is the reason for this behaviour?
>
> You sure about that, the above should yield 1 months and 1 days since you
> have an extra day there:
>
> ÙèªÔ×_
> c¢�Å€http://sandbox.onlinephpfunctions.com/code/fe7c7d989101ab5e1dd1530d457bfcc7a1cfa8fa
But see <https://3v4l.org/N5fg7>!
--
Christoph M. Becker