Bug #73120 [Opn]: Wrong calculation
| From: | jhdxr@php.net | Date: | Fri, 25 Nov 2016 19:31:48 +0000 |
| Subject: | Bug #73120 [Opn]: Wrong calculation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205642@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73120&edit=1
ID: 73120
Updated by: jhdxr@php.net
Reported by: carletto90 at gmail dot com
Summary: Wrong calculation
Status: Open
Type: Bug
Package: Date/time related
Operating System: Windows 10
PHP Version: 7.0.11
Block user comment: N
Private report: N
New Comment:
the current result is strange, but why the correct result is 1 month?
2016-03-31 - 2016-03-01 ==> 30 days
2016-04-01 - 2016-03-01 ==> 1 month
I think this is the correct calculation.
Previous Comments:
------------------------------------------------------------------------
[2016-09-20 08:25:18] carletto90 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/datetime.diff
---
Test script:
---------------
<?php
$date = new \DateTime('2016-03-01');
$date2 = new \DateTime('2016-03-31');
$diff = $date->diff($date2);
echo 'Years: '.$diff->y."\n";
echo 'Months: '.$diff->m."\n";
echo 'Days: '.$diff->d."\n";
?>
Expected result:
----------------
Years: 0
Months: 1
Days: 0
Actual result:
--------------
Years: 0
Months: 1
Days: 1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73120&edit=1