Skip to content

Instantly share code, notes, and snippets.

@jholloway7
Created November 30, 2016 15:56
Show Gist options
  • Save jholloway7/c5f851d60bdc51b2b9812dfe1d29bb38 to your computer and use it in GitHub Desktop.
Save jholloway7/c5f851d60bdc51b2b9812dfe1d29bb38 to your computer and use it in GitHub Desktop.
from datetime import datetime, timedelta
def is_between(dttm, begin, end):
begin_check = datetime.combine(dttm.date(), begin)
end_check = datetime.combine(dttm.date(), end)
# Handle the case where the range crosses midnight (or both times given are
# the same, assuming semantically you want this mean a 24-hr range instead
# of a null range that always returns False)
if end <= begin:
end_check += timedelta(days=1)
return begin_check <= dttm <= end_check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment