3
In PHP when I try to return the running days of a month I only get the future days:
$inicio = new DateTime('2019-11-12');
$fim = clone $inicio;
$fim->add(new DateInterval('P1M')); // intervalo de 1 mês
$intervaloPeriodo = DateInterval::createFromDateString('1 day'); // período de 1 dia
$periodo = new DatePeriod($inicio , $intervaloPeriodo, $fim);
foreach ($periodo as $p) {
echo $p->format("Y-m-d") . "<br />";
}
The return of the above code are the dates in the interval of 1 month increasingly:
/*
data exemplo: 2019-11-12
- 2019-11-12
- 2019-11-13
- 2019-11-14
- 2019-11-15
...
- 2019-12-11
*/
But the loop I need is the past days of the month in question (decreasing):
/*
data exemplo: 2019-11-12
- 2019-11-12
- 2019-11-11
- 2019-11-10
- 2019-11-09
...
- 2019-10-13
*/
What happens is that the period works only if it is the period positive/later but I need the period negative/previous month-long.
Note: setting the day as -1 (DateInterval::createFromDateString('-1 day')
)
doesn’t work, it goes into a loop and does not return the expected result.
Does anyone know how to solve this problem or other way to implement this date period?
https://stackoverflow.com/a/2338289/4734177
– gustavox
Thank you very much!
– Igor Dias