I have some problem,
I use python.
I have 2 var, like
ads = fields.Date('Admission Date', help='Date of admission')
dds = fields.Date('Discharge Date', help='Date of discharge')
I have one var to subtract the date,
los=ads-dds
but, I have some error:
unsupported operand type(s) for -: 'datetime.datetime' and 'datetime.date'
what should I do to get the result of los?
One of those fields is a
dateobject, the other adatetimeobject. You’ll have to decide what you want subtraction to mean.You could, for example, turn the
dateobject into adatetimeobject with a fixed time of day, say, midnight:datetime.datetime.combine()takes adateand atimeobject and creates a newdatetimeobject; we usedatetime.time.minas an easy short-cut to atimeobject representing midnight.Or, you could just turn the
datetimeobject into adateobject and then subtract:The
datetime.date()method returns just the date component of adatetimeobject. The result is adatetime.timedelta()object representing the number of days between the two dates.