Re: [PHP] Strange Result of Datetime::diff

[email protected] (Ryan Pallas)
Newsgroups php.general
Message-ID <CAObuZduF6gB4zoHXZRbKiuqNQfCZ40+j_N4Ys23ZPXAo2KgePA@mail.gmail.com>
On Apr 3, 2017 9:29 AM, <[email protected]> wrote:

Am 03-Apr-2017 15:28:44 +0200 schrieb [email protected]:
>
> On Mon, Apr 3, 2017 at 8:39 AM, <[email protected]> wrote:
> > Hi,
> >
> > 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?
> >
> > Thanks in advance and best regards
> > Christian
> > ------------------------------------------------------------
-------------------------------------
> > FreeMail powered by mail.de - MEHR SICHERHEIT, SERIOSITÄT UND KOMFORT
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> You sure about that, the above should yield 1 months and 1 days since you
have an extra day there:
>
> http://sandbox.onlinephpfunctions.com/code/fe7c7d989101ab5e1dd1530d457bfc
c7a1cfa8fa
>
> If it was:
>
> $date1 = new DateTime('2017-03-01');
> $date2 = new DateTime('2017-04-01');
>
> Then it would be exactly 1 month.
>

Aaw, of course you are right. I changed the code for another test and
forgot  to revert the change when I copied it into the mail.

So it seems like there is a bug. But what makes me wonder is that HHVM
prints out the same result. That's why I wanted to ask this mailing list as
I assume that I am missing something :-/

Does anyone have an idea?


What time zone are you using? The difference may be related to daylight
savings/summer time as that changed in that specific period.


Best regards
Christian
------------------------------------------------------------
-------------------------------------
FreeMail powered by mail.de - MEHR SICHERHEIT, SERIOSITÄT UND KOMFORT

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.