I'm trying to get a value from one of my database values, which will be given by subtracting the purchase date from today's date. I've written my code this way:
delta = datetime.now() - item.purchase_date
But this gives me this error:
unsupported operand type(s) for -: 'datetime.datetime' and 'datetime.date'
If I use datetime.datetime.now()
this doesn't work. What am I missing. Thanks.
you need to use date.today
or datetime.now().date()
instead of datetime.now
:
>>> import datetime
>>> datetime.date.today()
datetime.date(2010, 2, 10)
>>> datetime.datetime.now().date()
datetime.date(2010, 2, 10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With