+ 2
Why this result always in a kind of: TypeError: unsupported opperand type (s) for - : 'datetime.delta' and 'int'
Code: from datetime import date print "Starting.." release = date (2017, 8,21) now = date.today () until = release - now nights = until - 1 print " [*] Days until release: %s" % (until) print " [*] Nights until release: %s" % (nights) >>> nights = until - 1 (rest see above) i did release - now. this returns no TypeError because both are datetime/date objects? Plztell me, if this is the right Error- cause if no: give me please a note/start-up what it could be if yes: same like yes but note how to solve it.
2 Answers
+ 2
Yes, the release-now works because they are both dates, until-1 doesn't work because it doesn't know how to subtract an int from a date (which makes sense because it could mean 1 day, 1 week, 1 month...) use timedelta.
from datetime import timedelta
until-timedeltaâ(days=1)
+ 2
Thank you. I learned much about timedelta, time and date.
If anyone got a similar problem, people can take a look how i solved it, in "intro".