I am using PHP and Carbon and would like to check if two dates fall between another two dates.
As an example, say I have:
$eventStart = '2023-04-01';
$eventEnd = '2023-09-14';
$rangeStart = '2023-07-01';
$rangeEnd = '2023-07-31';
The ‘event’ which runs from 1st April until 14th September, does fall within the ‘range’ I want to check, which starts on 1st July up to 31st July.
So given any two start and end ‘event’ dates, how can I check that they fall within another two start and end ‘range’ dates?
2
Answers
You can use
CarbonPeriod::contains()
You should use
CarbonPeriod::overlaps()