I need to get a next month payment date right. So I'm taking the last due date and adding a month to it. How can I do it?
My example is: last payment was 31-st of Januarry, I'm doing
Carbon::create(2018, 1, 31, 0, 0, 0)->addMonthsNoOverflow(1)
and it works, it gives 2018-02-28
but after that next payment will be due on 28-th again. So I need to set a date after I'm adding a month.
Carbon::create(2018, 2, 28, 0, 0, 0)->addMonthsNoOverflow(1)->day(31)
it gives me 2018-03-31
which is good but if I use this formula with the first example
Carbon::create(2018, 1, 31, 0, 0, 0)->addMonthsNoOverflow(1)->day(31)
it gives me overflow 2018-03-03
. And this is my problem. What should I do? Is there something like ->setDayNoOverflow(31)
?
->endOfMonth()
for your example, but still I would suggest you to count month as 30 days. It's simple to add, simple to calculate, no brainf*cking both for you, and customers :) – Spasmodic