1

In Python:

  1. How check if current date and time is after a given date and time object named "next_check"
  2. Add X number of minutes to next check

1 Answers1

3

You can do both of those things with datetime (assuming you import datetime and next_check is actually a datetime.datetime instance):

  1. if datetime.datetime.now() > next_check; and
  2. next_check += datetime.timedelta(minutes=X).

If it isn't a datetime.datetime instance, that module contains various functions (e.g. strptime) to make it into one.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 1
    Use `.utcnow()` or `.now(timezone.utc)` (if `next_check` is a naive datetime object; it also should be in UTC) instead of `.now()`. Depending on where `next_check` comes from, comparing it with local time (`.now()`) is either always wrong or just during DST transitions. See [Daylight saving time and time zone best practices](http://stackoverflow.com/q/2532729/4279). – jfs May 05 '14 at 07:37