Bug #81527 [NEW]: DateTime::diff returns different results when called on both objects.
From: victor dot todoran at yahoo dot com
Operating system: Ubuntu 20.04
PHP version: 7.4.24
Package: Date/time related
Bug Type: Bug
Bug description:DateTime::diff returns different results when called on both objects.
Description:
------------
DateTime::diff returns different results when called on both objects.
Test script:
---------------
<?php
$date1 = new \DateTime('2015-10-25', new \DateTimeZone('UTC'));
$date2 = new \DateTime('2017-10-24', new \DateTimeZone('UTC'));
$diff1 = $date1->diff($date2);
$diff2 = $date2->diff($date1);
echo $diff1->y . ' years ' . $diff1->m . ' months ' . $diff1->d .
' days
'; // outputs 1 years 11 months 29 days
echo PHP_EOL;
echo $diff2->y . ' years ' . $diff2->m . ' months ' . $diff2->d .
' days
'; // outputs 1 years 11 months 30 days
Expected result:
----------------
1 years 11 months 29 days
1 years 11 months 29 days
or
1 years 11 months 30 days
1 years 11 months 30 days
I would expect the number of days to be identical.
Actual result:
--------------
The number of days differs
1 years 11 months 29 days
1 years 11 months 30 days
--
Edit bug report at https://bugs.php.net/bug.php?id=81527&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81527&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81527&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81527&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81527&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81527&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81527&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81527&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81527&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81527&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81527&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81527&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81527&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81527&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81527&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81527&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81527&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81527&r=mysqlcfg
Thread (3 messages)
- victor dot todoran at yahoo dot com