Bug #73120 [Opn->Fbk]: Wrong calculation
| From: | derick@php.net | Date: | Sun, 12 Feb 2017 18:12:50 +0000 |
| Subject: | Bug #73120 [Opn->Fbk]: Wrong calculation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207287@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: derick@php.net
Reported by: carletto90 at gmail dot com
Summary: Wrong calculation
-Status: Open
+Status: Feedback
Type: Bug
Package: Date/time related
Operating System: Windows 10
PHP Version: 7.0.11
Block user comment: N
Private report: N
New Comment:
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php
If you can provide more information, feel free to add it
to this bug and change the status back to "Open".
Thank you for your interest in PHP.
I can't reproduce this:
derick@whisky:~/dev/timelib $ php
<?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";
?>
Years: 0
Months: 0
Days: 30
Which timezone have you configured?
Previous Comments:
------------------------------------------------------------------------
[2016-11-25 19:31:47] jhdxr@php.net
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.
------------------------------------------------------------------------
[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