0

I understand my question title may be a little vague so let me explain.

I need to check to see if an object has gone past a certain date. Now here's what makes it complicated. When the object is added to the model it's only done so with a string date not actually formatted as a date. It's coming from CSV so it's the only way I can do this.

It will always be formatted as M-DD-YY.

Now, what I need to check for is to see if a reset has happened. Resets occur every Wednesday at 4am CEST. So when I'm looking at the model I can have it set as two things.

  1. Expired objects (from the previous reset)

  2. Current objects (that will not reset until next Wednesday)

I really can't figure out the best way to tackle this and I am open to ideas and suggestions.

Thank you.

Llanilek
  • 3,386
  • 5
  • 39
  • 65

1 Answers1

1

Convert the field into a datetime in code using dateutil.parser before comparing it to the current date:

from dateutil import parser
from datetime import datetime

object_date = parser.parse(my_obj.datefield)
if object_date < datetime.now():
    # Do something
else:
    # Do something else

You can install dateutil using pip install python-dateutil

hellsgate
  • 5,905
  • 5
  • 32
  • 47
  • This doesn't answer the question of knowing dynamically when the next reset date is. – Llanilek Sep 24 '13 at 15:55
  • Have a look at the first answer (including comments) of http://stackoverflow.com/questions/8708058/python-given-a-date-and-weekday-find-the-date-of-the-next-occurrence-of-a-given – hellsgate Sep 24 '13 at 16:02
  • That's pointed me in the right direction. Thank you very much. :D – Llanilek Sep 24 '13 at 21:42