|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-27 15:13 UTC] jennifer dot kimball at nrc dot ca
Description:
------------
DatePeriod should be able to create a list of dates that goes into the future from the start date, or into the past from the start date. There is nothing in the documentation to suggest this should not be possible, and trying it does not throw an error.
Given that a question like 'What are the dates of the previous 3 Saturdays' is fairly common, it seems sensible that DatePeriod be able to calculate that way.
Reproduce code:
---------------
---
From manual page: dateperiod.construct#Description
---
//postive interval works:
$d1=date_create('2004-12-25');
$i=DateInterval::createFromDateString('1 year');
$d2=date_create('2009-03-03');
$p=new DatePeriod($d1,$i,$d2);
foreach($p as $d) echo $d->format('Y-m-d');
//negative interval fails with no error
$d1=date_create('2009-12-25');
$i=DateInterval::createFromDateString('-1 year');
$d2=date_create('2004-03-03');
$p=new DatePeriod($d1,$i,$d2);
foreach($p as $d) echo $d->format('Y-m-d');
Expected result:
----------------
//postive interval output (which does happen)
2004-12-25
2005-12-25
2006-12-25
2007-12-25
2008-12-25
//negative interval output (which does not happen)
2009-12-25
2008-12-25
2007-12-25
2006-12-25
2005-12-25
2004-12-25
Actual result:
--------------
//no output
//no error
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 21:00:02 2025 UTC |
You are mistaken. This is the faulty line: $i=DateInterval::createFromDateString('-1 year'); DateInterval::createFromDateString doesn't report any error when it fails. Fix your DateInterval first :)