I want Excel to check whether two time intervals intersects or not.
For example, I3-J3 and I5-J5 intersects.
How can I make Excel to show this intersection in another cell?
I want Excel to check whether two time intervals intersects or not.
For example, I3-J3 and I5-J5 intersects.
How can I make Excel to show this intersection in another cell?
The following formula will reveal any interference for the last row. Just copy this formula into cell K3
and copy it down:
=IF(OR(AND(OR(I3>(I$2:I2)),OR(I3<(J$2:J2))),AND(OR(I3>(I$2:I2)),OR(I3<(J$2:J2)))),"interference","OK")
Note that this is an array formula which will have to be entered using Ctrl
+ Shift
+ Enter
. For more information on array formulas you might want to read the following article: https://support.office.com/en-us/article/Guidelines-and-examples-of-array-formulas-7D94A64E-3FF3-4686-9372-ECFD5CAA57C7
If you want to show interference
for both rows then you'd have to expand upon I$2:I2
and J$2:J2
to include the entire list. So, this might be (for example) I$2:I$500
and J$2:J$500
respectively. Yet, you cannot include the row itself. Otherwise, you'd always get interference
because the formula would check against itself. So, you'd have to generate individual formulas for each row and you cannot enter a generic formula and copy it down.
I am not sure how to show (with formulas only) the interfering entry. This is mostly due to the fact that there might be more than one interfering entry which would then have to be listed and separated by ,
. I don't think that can be done with formulas only.
Note: the above solution is based on the basic principle that all dates and times in Excel are (essentially) just numbers formatted as dates or time. For more information you might want to read the following: Change date format using substitute or replace
So, the above formula is just checking if the date in column I
is between any prior date in column I
and column J
. If the date in column I
is >
and prior date in column I
and also <
compared to the date in column J
then this is an interference. The same has to be checked for the date in column K
and then both have to be combined with an OR
. That's the entire formula above.
Based on the comment provided by @Gordon the formula can be improved with the COUNTIFS
function. Just enter the following formula into cell C2
and copy it down:
=SUM(COUNTIFS(A:A,"<"&A2,B:B,">"&A2),COUNTIFS(A:A,"<"&B2,B:B,">"&B2))
Any number greater than 0
means that there is at least one interference. With this formula it is now counting / showing multiple interferences as you can see in the following screenshot:
Note, that the improved formula does not require anymore for you to know the range of the table. Instead you can search the entire column A:A
and B:B
for interferences.
I'd like to improve formula that was provided by @Ralph. That formula considers only two intersection situations - when time intervals overlap. But there are two more situations of intersection:
So the final formula for me looks like this:
=SUM(COUNTIFS(A:A, "<"&A2, B:B, ">"&A2), COUNTIFS(A:A, "<"&B2, B:B, ">"&B2), COUNTIFS(A:A, ">"&A2, B:B, "<"&B2), COUNTIFS(A:A, "<"&A2, B:B, ">"&B2))