Req #67663 [Opn->Wfx]: DatePeriod not giving correct date
| From: | salathe@php.net | Date: | Tue, 22 Jul 2014 08:14:46 +0000 |
| Subject: | Req #67663 [Opn->Wfx]: DatePeriod not giving correct date | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186769@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67663&edit=1
ID: 67663
Updated by: salathe@php.net
Reported by: hharrysidhu at gmail dot com
Summary: DatePeriod not giving correct date
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: *General Issues
+Package: Date/time related
Operating System: Windows
PHP Version: 5.5.14
Block user comment: N
Private report: N
New Comment:
The "P1M" interval does the only sensible thing it can; it increments the month number
only. "2015-01-31" + "P1M" gives "2015-02-31", which is not a valid
date so the normal "roll over" behaviour occurs to give the resulting date of
"2015-03-03".
The feature request made here, to "give [you] 31 of every month by skipping February"
seems like a very strange determination of "correct" behaviour and will not be something
that we support.
Previous Comments:
------------------------------------------------------------------------
[2014-07-22 02:52:34] chris at cgsmith dot net
By doing format("U") I found that P1M equals 2,678,400 seconds. It looks like
'P1M' is literally translated into '31 days'
------------------------------------------------------------------------
[2014-07-21 20:52:36] hharrysidhu at gmail dot com
Description:
------------
$begin = new DateTime( '2014-12-31' );
$end = new DateTime( '2016-04-31');
$interval = new DateInterval('P1M');
$daterange = new DatePeriod($begin, $interval ,$end);
foreach($daterange as $date){
echo $date->format("Y-m-d") . "<br>";
}
This code should give me 31 of every month by skipping February.
It skips February but it changes actual date.
Test script:
---------------
$begin = new DateTime( '2014-12-31' );
$end = new DateTime( '2015-06-31');
$interval = new DateInterval('P1M');
$daterange = new DatePeriod($begin, $interval ,$end);
foreach($daterange as $date){
echo $date->format("Y-m-d") . "<br>";
}
Expected result:
----------------
2014-12-31
2015-01-31
2015-03-31
2015-05-31
Actual result:
--------------
2014-12-31
2015-01-31
2015-03-03
2015-04-03
2015-05-03
2015-06-03
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67663&edit=1