A booking ends at 10:00 and another begins at 10:00. Do they overlap? With a half-open time range, the answer is no: the end belongs to the next range. A booking from 09:30 to 10:30 does overlap a request starting at 10:00.
Use pandas.IntervalIndex.overlaps() to check each booking against one requested slot. The example below keeps the booking IDs, makes the endpoint rule explicit, and rejects missing or reversed times before returning a result.

Choose what happens at an endpoint
We will represent every booking as [start, end). The square bracket includes the start; the parenthesis excludes the end. In pandas, closed="left" applies that rule. Set it explicitly on both the existing bookings and the requested slot.
For positive-length half-open ranges, an overlap requires both of these conditions:
booking_start < requested_end
requested_start < booking_end
The strict comparisons make the boundary matter. A01 ends exactly when the request starts, so it fails the second condition. A04 starts exactly when the request ends, so it fails the first.
Start with four fictional bookings
| Booking | Start | End |
|---|---|---|
| A01 | 09:00 | 10:00 |
| A02 | 10:00 | 11:00 |
| A03 | 09:30 | 10:30 |
| A04 | 11:00 | 12:00 |
The requested slot is 10:00–11:00 on the same date. The code includes the full dates because comparing clock times alone would lose the distinction between today and tomorrow.
Parse the times and flag overlaps
Run this block in a Python session with pandas installed. It copies the input, so the original booking table remains available. Invalid timestamp text raises a parsing error; missing endpoints or a start that is not earlier than its end raise the message defined in the function.
import pandas as pd
bookings = pd.DataFrame({
"booking": ["A01", "A02", "A03", "A04"],
"start": ["2026-11-28 09:00", "2026-11-28 10:00",
"2026-11-28 09:30", "2026-11-28 11:00"],
"end": ["2026-11-28 10:00", "2026-11-28 11:00",
"2026-11-28 10:30", "2026-11-28 12:00"],
})
def mark_overlaps(frame, requested_start, requested_end):
result = frame.copy()
time_format = "%Y-%m-%d %H:%M"
start = pd.to_datetime(result["start"], format=time_format, errors="raise")
end = pd.to_datetime(result["end"], format=time_format, errors="raise")
invalid = start.isna() | end.isna() | start.ge(end)
if invalid.any():
raise ValueError("Each booking needs a nonmissing start earlier than its end.")
bounds = pd.to_datetime(
[requested_start, requested_end], format=time_format, errors="raise"
)
if bounds.isna().any() or bounds[0] >= bounds[1]:
raise ValueError("The request needs a nonmissing start earlier than its end.")
intervals = pd.IntervalIndex.from_arrays(start, end, closed="left")
request = pd.Interval(bounds[0], bounds[1], closed="left")
result["overlap"] = intervals.overlaps(request)
return result
result = mark_overlaps(bookings, "2026-11-28 10:00", "2026-11-28 11:00")
print(result.to_string(index=False))
Output:
booking start end overlap
A01 2026-11-28 09:00 2026-11-28 10:00 False
A02 2026-11-28 10:00 2026-11-28 11:00 True
A03 2026-11-28 09:30 2026-11-28 10:30 True
A04 2026-11-28 11:00 2026-11-28 12:00 False
The function compares each booking with the requested slot in its existing row order. It does not compare every booking with every other booking. The returned overlap column is a Boolean flag, not the number of minutes shared.
Read the flags before filtering
A02 overlaps because it has exactly the requested start and end. A03 overlaps during the half hour from 10:00 to 10:30. A01 and A04 merely touch the requested slot at opposite endpoints.
To review the matches, select the flagged booking IDs:
conflicts = result.loc[result["overlap"], "booking"].tolist()
print(conflicts)
Output:
['A02', 'A03']
These two bookings share time with the request. It does not decide whether the request can be accepted. That also depends on whether these bookings use the same room, person, machine, or other limited resource.
Reject invalid ranges rather than marking them free
A missing end time does not tell you that a booking has ended. The function stops instead of quietly treating that row as available. This tutorial also requires every booking and request to have positive duration. A start equal to its end is rejected under that policy.
bad = bookings.copy()
bad.loc[0, "end"] = bad.loc[0, "start"]
try:
mark_overlaps(bad, "2026-11-28 10:00", "2026-11-28 11:00")
except ValueError as error:
print(error)
Output:
Each booking needs a nonmissing start earlier than its end.
Do not automatically swap reversed endpoints. An end before a start could be a mistyped date or a booking that crosses midnight with its second date omitted. Correct the source or supply the actual next-day date before comparing it.
Keep the time rule separate from the booking rule
If both endpoints are included, ranges that share an endpoint overlap at that instant. Use the closure that matches the question you are answering. For a required setup or cleanup gap, the gap needs its own explicit rule; changing a bracket does not add 15 minutes.
The input here uses local timestamps without time-zone information, all on the same known clock. For exports containing UTC offsets, first put the timestamps on a consistent time basis. This function does not resolve ambiguous daylight-saving times.
If the task is to attach the latest earlier status to each event rather than compare periods, see matching events to the latest prior record in pandas. That is a different selection rule.
The examples were executed with Python 3.11.3 and pandas 2.3.3.
Further reading
- pandas documentationIntervalIndex.overlapsCompare each range with another interval and read the returned flags.
- pandas documentationIntervalIndex.from_arraysConstruct ranges from start and end arrays with an explicit closure.
- pandas documentationto_datetimeCheck date formats, parsing errors, missing values, and time-zone behavior.