python django subtract timedelta object from datetime object?

Go To StackoverFlow.com

0

A python/django beginner's question:

I have a datetime object (drive_date), a time object (start_time) and a timedelta object (when_to_notify).

I first do this:

d = datetime.combine(l.drive_date, l.start_time)

I would then like to subtract the "when_to_notify" timedelta object from d to get a notification date and time. However, django doesn't like this. It tells me: TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.timedelta'

How can I subtract the time in the timedelta object from a datetime object?

2012-04-05 01:52
by mb52089


1

[moved from comment section]

datetime.combine returns a datetime from which a datetime.timedelta can be subtracted. From the exception it seems you are trying to subtract a datetime.timedelta from a time object instead of a datetime object. Can you recheck?

2012-04-05 17:05
by mshsayem
Ads