Check time difference between now and specified time


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. from datetime import datetime, timedelta
  2.  
  3. now = datetime.now()
  4. sometime_in_the_future = datetime(2020, 1, 1, now.hour, now.minute, now.second)
  5. MAX_AGE = timedelta(hours=2, minutes=0)
  6. if (now - sometime_in_the_future) > MAX_AGE:
  7. return True
  8. else:
  9. return False

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.