confused on calculating date difference in days.

Diez B. Roggisch deets at nospam.web.de
Tue Oct 16 10:06:22 EDT 2007


krishnakant Mane wrote:

> hello,
> thanks all of you for providing valuable help.
> right now I am confused about the delta object.
> how can I extract the difference between two dates in terms of day
> using the delta object?
> I tried reading the python docs but did not understand the concept of
> delta object and how can I measure the difference in terms of days
> between two dates.
> I expect that the days would be integers.
> secondly the format of my date is actually "16/10/2007", and this is
> all in varchar field inside a postgresql database.
> I understand that datetime.datetime.strptime would convert this string
> "16/10/2007" into a date object which I can then compare with the
> current date created by datetime.now().
> is that right?
> if yes then please explain me how I can get the delta object to give
> me results in days.

The documentation is very clear about this:

http://docs.python.org/lib/datetime-timedelta.html

"""
Instance attributes (read-only):

days  Between -999999999 and 999999999 inclusive
seconds  Between 0 and 86399 inclusive
microseconds  Between 0 and 999999 inclusive
"""

So (date_a - date_b).days will give you what you need.

Diez



More information about the Python-list mailing list