TypeError: unsupported type for timedelta days component: datetime.datetime

python

Solution

`summing_period` should be an integer (representing the number of days), not a `datetime` object.

>>> timedelta(days=datetime.now())
TypeError: unsupported type for timedelta days component: datetime.datetime

>>> timedelta(days=5)
datetime.timedelta(5)

Problem

I am trying to perform some date arithmetic in a function. ``` from datetime import datetime, timedelta def foo(date1, summing_period): current_period_start_date = date1 - timedelta(days=summing_period) # Line above causes the error: # TypeError: unsupported type for timedelta days component: datetime.datetime ``` First arg is a datetime obj and 2nd arg is an integer What is causing this error, and how do I fix it?

Original source