A common problem in PHP (maybe in some other langs too) is the way to move between dates and get the incorrect value, for example when you decrease or increase a month(s):
>>> (new \DateTime('2017-01-31'))->add(new \DateInterval('P1M'))->format('Y-m-d') => "2017-03-03"
Carbon a good library offers some methods to avoid this behaivor and their names are really good:
>>> (new Carbon('2017-01-31'))->addMonthNoOverflow()->format('Y-m-d') => "2017-02-28"
If you wanna get the calculation with this behaivor, no problem:
>>> (new Carbon('2017-01-31'))->addMonthWithOverflow()->format('Y-m-d') => "2017-03-03"
Other methods are: createMidnightDate, localeHasDiffOneDayWords, createSafe...
createMidnightDate
localeHasDiffOneDayWords
createSafe
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A common problem in PHP (maybe in some other langs too) is the way to move between dates and get the incorrect value, for example when you decrease or increase a month(s):
Carbon a good library offers some methods to avoid this behaivor and their names are really good:
If you wanna get the calculation with this behaivor, no problem:
Other methods are:
createMidnightDate
,localeHasDiffOneDayWords
,createSafe
...