|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-07-21 20:52 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 05:00:01 2025 UTC |
By doing format("U") I found that P1M equals 2,678,400 seconds. It looks like 'P1M' is literally translated into '31 days'