Req #67663 [Com]: DatePeriod not giving correct date

From: Date: Tue, 22 Jul 2014 02:52:35 +0000
Subject: Req #67663 [Com]: DatePeriod not giving correct date
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186767@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 Comment by: chris at cgsmith dot net Reported by: hharrysidhu at gmail dot com Summary: DatePeriod not giving correct date Status: Open Type: Feature/Change Request Package: *General Issues Operating System: Windows PHP Version: 5.5.14 Block user comment: N Private report: N New Comment: By doing format("U") I found that P1M equals 2,678,400 seconds. It looks like 'P1M' is literally translated into '31 days' Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#186767) next »