lower = bisect.bisect_right(dates, datetime.datetime(2007, 1, 3))
upper = bisect.bisect_left(dates, datetime.datetime(2007, 1, 6))
mask = dates[lower:upper]
mask
Compare list of datetimes with datetime in Python