I'm curious about manipulating time in Python. I can get the (last modified) age of a file using the
import os.path, time
If you need to have the exact number of days you can use the
calendar module in conjunction with datetime, e.g.,
import calendar import datetime def total_number_of_days(number_of_months=3): c = calendar.Calendar() d = datetime.datetime.now() total = 0 for offset in range(0, number_of_months): current_month = d.month - offset while current_month <= 0: current_month = 12 + current_month days_in_month = len( filter(lambda x: x != 0, c.itermonthdays(d.year, current_month))) total = total + days_in_month return total
And then feed the result of
total_number_of_days() into the code that others have provided for the date arithmetic.