how can I check the difference between two dates using the datetime modules? (or any other module that would do the same thing).
I want to read a date from a file (which was written in the same format as the datetime module uses) and then calculate the difference in days between that date and today.

>>> import datetime
>>> dir(datetime)
['MAXYEAR', 'MINYEAR', '__doc__', '__name__', '__package__', 'date', 'datetime', 'datetime_CAPI', 'time', 'timedelta', 'tzinfo']
>>> #Use method date and timedelta
>>> print datetime.date.today()
2010-01-11
>>>
>>> #Find now days since 1 Jan 1901 
>>> one_day = datetime.timedelta(days=1)
>>> long_time_ago = datetime.date(1901, 1, 01)
>>> print to_day - long_time_ago
39822 days, 0:00:00

I'm afraid I don't understand that example.. what is 'to-day'? It hasn't been defined earlier.

thanks for your help. Your link and a little more rummaging in the python documentation worked. It turns out you can just subtract two date objects and that will return a timedelta object.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.