I just asked this question and it was marked as already answered but whoever did that obviously did not understand the question.
This post was marked as a duplicate question to this,
but they are not even remotely the same.
I'm looking for the amount of overlapping time in two DatePeriods not the difference between two dates.
A "DatePeriod" consists of two dates and I'm looking for the amount of overlap between two DatePeriods.
There is another post I found that answers half of my question here,
and it works great but it does not give me the amount of time overlap between the two date ranges. It only determines if they overlap or not. I need to know the amount of minutes that they overlap. So Here is my original question...
I assumed there would be a very easy way to do this but I have looked all over and can not find a solution. The logic is simple: find the amount of overlapping minutes given two DatePeriods.
For example,
-I have $startDate1
and $endDate1
as the first date range.
-I have $startDate2
and $endDate2
as the second date range.
(For demonstration sake, the format is 'Y-m-d H:i'
. )
Suppose
$startDate1 = '2015-09-11 09:15'
and$endDate1 = '2015-09-13 11:30'
.Suppose
$startDate2 = '2015-09-13 10:45'
and$endDate2 = '2015-09-14 12:00'
.
I would expect a result of 45 minutes overlap. How can this be achieved?
I have seen this done using two DateTimes but that is not what I'm looking for.
A datePeriod consists of two DateTimes and I'm looking for the difference between two DatePeriods.