I've been searching around before asking this.
I have Django template, which inputs a water account number, a beginning date, and an ending date. The dates define a search range, and are in mm/dd/yyyy format.
I'd like to convert these dates into a Python format, so I can find the difference between them. I'm aware of date and datetime objects, and I know I can parse -- for example -- 05/01/2012 -- and create a date object from that.
However, I'm interested in a better way to this, like converting the "05/01/2012" directly for start and end date range values, and then taking the delta between those Python date objects.
Thank you.
Edit: This is what I'm using to calculate the delta:
d1 and d2 are date strings in the form: mm/dd/yyyy.
def time_delta(d1, d2):
dd1 = datetime.strptime(d1, "%m/%d/%Y").date()
dd2 = datetime.strptime(d2, "%m/%d/%Y").date()
delta = dd2 - dd1
return delta.days