-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Carbon v3 diffInDays is not consistent #2971
Comments
I see different results as well in Laravel Laravel 10 with Carbon 2 > now()->addMonths(12)->diffInMinutes(now())
= 525599 Laravel 11 with Carbon 3 > now()->addMonths(12)->diffInMinutes(now())
= -525599.99999737 Notice carbon 3 results in negative value P.S - All of diff methods are resulting in negative values Related #2119 |
Hello @ankurk91 it's a different concern. The difference in the original post above happens because of daylight saving time (I'm currently evaluating how to best handle that so the result may change in the future). But the difference you get is expected, in Carbon 2, the diff was always
No If you want positive/absolute value, you can use one of the options below: // Swapping dates so current < other
$value = now()->diffInMinutes(now()->addMonths(12));
// Explicit absolute so it's positive no matter if other is > or < than current
$value = now()->addMonths(12)->diffInMinutes(now(), true);
$value = abs(now()->addMonths(12)->diffInMinutes(now())); Then from this |
Thank you for this, and also for taking care of it so quickly |
Hello,
I encountered an issue with the following code:
Carbon version: 3.1.1
PHP version: 8.1.23
I expected to get:
But I actually get:
So, technically it is correct that it is fewer than 10 days between midnight on March 1 and March 11 in Eastern Time; however there are situations where you are dealing with 2 dates where you want to get the difference between the two and it isn't always obvious why you aren't getting the correct results.
Thanks!
The text was updated successfully, but these errors were encountered: