I have a specific date - for this example say July 6. It falls in week 27 in the year 2016. Using PHP 5.5.9 I am trying to return the 7 dates that occur in that week, using the following function:
function getStartAndEndDate($week, $year) {
$i=0;
$dto = new DateTime();
$ret[$i] = $dto->setISODate($year, $week)->format('Y-m-d');
$i++;
while ( $i < 7 ){
$ret[$i] = $dto->modify('+' . $i . ' days')->format('Y-m-d');
$i++;
}
return $ret;
}
I am expecting a list of 7 sequential dates from 2016-07-04 to 2016-07-10
Instead, I am receiving the following dates: 2016-07-04, 2016-07-05, 2016-07-07, 2016-07-10 2016-07-14 2016-07-19, 2016-07-25
I believe the following line is the source of my problem:
$ret[$i] = $dto->modify('+' . $i . ' days')->format('Y-m-d');
When I specify static values, the code works.
Any suggestions, or insights would be appreciated.
Thank you