Posted By

magicrebirth on 11/28/10


Tagged

time timedelta


Versions (?)

Check time difference between now and specified time


 / Published in: Python
 

  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  

You need to login to post a comment.