最佳答案
What is the difference between datetime.timedelta
(from Python's standard library) and dateutil.relativedelta.relativedelta
when working only with days?
As far as I understand, timedelta
only supports days (and weeks), while relativedelta
adds support for periods defined in terms of years, months, weeks or days, as well as defining absolute values for year, month or day. (remember, for the purposes of this question, I don't have to worry about hours, minutes or seconds)
Considering that I'm only working with datetime.date
objects, and only interested in periods defined by the number of days, what's the difference between timedelta
and relativedelta
? Is there any difference?
from datetime import date, timedelta
from dateutil.relativedelta import relativedelta
i = -1 # This could have been any integer, positive or negative
someday = date.today()
# Is there any difference between these two lines?
otherday = someday + timedelta(days=i)
otherday = someday + relativedelta(days=i)