How can I convert a dateutil.relativedelta object to a datetime.timedelta object?
e.g.,
# pip install python-dateutil
from dateutil.relativedelta import relativedelta
from datetime import timedelta
rel_delta = relativedelta(months=-2)
# How can I convert rel_delta to a timedelta object so that I can call total_seconds() ?
time_delta = ???(rel_delta)
time_delta.total_seconds() # call the timedelta.total_seconds() method
You can't, for one huge reason: They don't store the same information.
datetime.timedeltaonly stores days, seconds, and milliseconds, whereasdateutil.relativedeltastores every single time component fed to it.That
dateutil.relativedeltadoes so is important for storing things such as a difference of 1 month, but since the length of a month can vary this means that there is no way at all to express the same thing indatetime.timedelta.