I tried the code posted by larsmans above, but there are a few problems:
1) The code as it will cause an error, as mentioned by mauguerra 2) If you change the code to the following:
... d1 = d1.strftime("%Y-%m-%d") d2 = d2.strftime("%Y-%m-%d") return abs((d2 - d1).days)
This converts your datetime objects to strings, but two things
1) An attempt to execute d2 - d1 will fail, because you cannot use the minus operator for strings, and 2) If you read the first line of the above answer that you specified, you want to use the operator on two datetime objects, but you just convert them to strings
I found that you literally only need the following:
import datetime end_date = datetime.datetime.utcnow() start_date = end_date - datetime.timedelta(days=8) difference_in_days = abs((end_date - start_date).days) print difference_in_days
schalkneethling Oct 08 2018-12-12T00: 00Z
source share