Given a DateTime
instance initialized as :
$tgtDateDT = new DateTime('now');
which for example equates to 2023-01-30
when formatted as ->format("Y-m-d")
,
I want to advance the month to February (for rendering a calendar) where I was hoping to do:
$nextMonth = $tgtDateDT->add(new DateInterval('P1M'));
Which when formatted with ->format("Y-m-d")
yields
2023-03-02
So February has 28 days so I understand it may yield an unpredictable result.
So how can I take a date from any day in one month and advance it to say "the first" of the next month - preferably with DateInterval
.
For my calendar rendering the new date can be any day in the next month.