Skip to content

DateInterval d property is 0 instead of real value 28 #18183

Closed as not planned
Closed as not planned

Description

@bdtarcsa

Description

The following code:

<?php
$md_1st = new DateTime("2025-03-01");
  $md_last = new DateTime("2025-03-29");
  $mn_interval = $md_1st->diff($md_last);
echo $mn_interval->days . "  " . $mn_interval->d;

Resulted in this output:

28 0

But I expected this output instead:

28 28

PHP Version

Correction
not PHP 8.3.19 PHP 8.0.30 or 7.4.33

Operating System

linux (kernel ver.: 4.18.0-553.33.1.el8_10.x86_64)

Activity

  1. bdtarcsa commented on Mar 29, 2025

    @bdtarcsa
    Author

    Anyway, it is working well in 8.1.25

  2. ndossche commented on Mar 29, 2025

    @ndossche
    Member

    It works on my machine and on 3v4l: https://3v4l.org/EXC9L
    Is this maybe timezone related?

  3. bdtarcsa commented on Mar 29, 2025

    @bdtarcsa
    Author

    I do not know. Maybe. Based on DateTime object the timezone is Europe/Budapest:

    object(DateTime)#6 (3) {
    ["date"]=>
    string(26) "2025-03-01 00:00:00.000000"
    ["timezone_type"]=>
    int(3)
    ["timezone"]=>
    string(15) "Europe/Budapest"
    }
    object(DateTime)#7 (3) {
    ["date"]=>
    string(26) "2025-03-29 00:00:00.000000"
    ["timezone_type"]=>
    int(3)
    ["timezone"]=>
    string(15) "Europe/Budapest"
    }

  4. hormus commented on Apr 1, 2025

    @hormus

    DateTimeInterface::diff the date 2025-02-28 23:00:00 UTC (2025-03-01 00:00:00 Europe/Budapest) is used instead of the real time before php version 8.1..
    Why it happens to your php version 8.3.19 is hard to say. Please, Can you test what the timezone_version_get() function returns?

  5. bdtarcsa commented on Apr 10, 2025

    @bdtarcsa
    Author

    The timezone_version_get() function returns with this:
    2025.2

  6. bdtarcsa commented on Apr 10, 2025

    @bdtarcsa
    Author

    Sorry, I was looking at the wrong version number of PHP.

    Correct version numbers are 8.0.30 and 7.4.33.

    As I can see in the snipett the result is the same what I detected.

    On my dev machine the PHP version is 8.1.25 and timezone version is 2023.3 and there is no problem.

    And as I said earlier there was no problem in November for example or in last 8 years. Interesting.

  7. carlosbuenosvinos commented on Apr 13, 2025

    @carlosbuenosvinos
    Contributor

    I don't see the issue. As @nielsdos mentions, checking all PHP versions, behaviour is consistent.

    Image
  8. ndossche commented on Apr 13, 2025

    @ndossche
    Member

    Correct version numbers are 8.0.30 and 7.4.33.

    These versions have long been out of bugfix support, the lowest bugfix-supported version is 8.3.x. Given that this works in those versions I'm closing this as invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions