briannesbitt / Carbon

A simple PHP API extension for DateTime.

Home Page:https://carbon.nesbot.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please don't modify existing instances with date arithmetic methods

kpconnell opened this issue · comments

Hello,

I encountered an issue with the following code:

$startDate = Carbon::today()->subDays(10);
$endDate = $startDate->addDays(5);

Carbon version: 2.72.3

I expected to get:

a different end date than start date

But I actually get:

end and start date are the same.

commented

Use CarbonImmutable::today() instead, it's like DateTime vs. DateTimeImmutable. (See the very first chapter of the doc)