Just iterate over and change integer passed to addMonths method.
now()->addMonths(2)->endOfMonth()->toDateString();
or
now()->addMonths(2)->endOfMonth()->format('d-m-Y'); // formatted as you presented
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I ve spent the last couple of hours searching but i didn't find a solution on the following issue
i use CarbonPeriod and i cannot avoid the month overflow
ex: CarbonPeriod(Carbon::parse("31-1-2020),'1 month,'$from->addMonths(10)
i want to get the last day of every month till October but in February the date overflow to March so i get 31-1-2020 2-3-2020 2-4-2020 etc
I tried in AppServiceProvider Carbon::useMonthsOverflow(false); which didn't work
i think i am missing something here
can you adapt to use lastOfMonth ?
use 1st of month, add a month at a time, and get lastOfMonth()
Please or to participate in this conversation.