Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bdtarcsa opened this issue Mar 29, 2025 · 8 comments
Closed

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

bdtarcsa opened this issue Mar 29, 2025 · 8 comments

Comments

@bdtarcsa
Copy link

bdtarcsa commented Mar 29, 2025

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)

@bdtarcsa
Copy link
Author

Anyway, it is working well in 8.1.25

@nielsdos
Copy link
Member

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

@bdtarcsa
Copy link
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"
}

@hormus
Copy link

hormus commented Apr 1, 2025

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?

@bdtarcsa
Copy link
Author

The timezone_version_get() function returns with this:
2025.2

@bdtarcsa
Copy link
Author

bdtarcsa commented Apr 10, 2025

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.

@carlosbuenosvinos
Copy link
Contributor

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

Image

@nielsdos
Copy link
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.

@nielsdos nielsdos closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants