Skip to content

Instantly share code, notes, and snippets.

@lambdamusic
Created February 7, 2013 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambdamusic/4734295 to your computer and use it in GitHub Desktop.
Save lambdamusic/4734295 to your computer and use it in GitHub Desktop.
Python: Check time difference between now and specified time
from datetime import datetime, timedelta
now = datetime.now()
sometime_in_the_future = datetime(2020, 1, 1, now.hour, now.minute, now.second)
MAX_AGE = timedelta(hours=2, minutes=0)
if (now - sometime_in_the_future) > MAX_AGE:
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment