I would like to clarify that this inquiry is distinct from Calculate thenumber of months between two dates in phpbecause I am looking to determine the month each time the month number changes, rather than only when there is a 30-day gap between two dates. Please refer to the examples I ...
There is a handy way to compare intervals by adding them to 0 dates and comparing dates instead<?phpfunction compare(DateInterval $first, DateInterval $second): int{$firstDate = (new DateTime())->setTimestamp(0)->add($first);$secondDate = (new DateTime())->setTimestamp(0)->add($seco...
$string = 'first day of next month'; if (strtotime($string) === false) { echo "'$string' is not a valid date/time string."; } elseif (Carbon::hasRelativeKeywords($string)) { echo "'$string' is a relative valid date/time string, it will returns different dates depending on the...