I'm making a query to get the number of days from the date that a person bought a new phone until today.
device_record = Devc.objects.annotate(duration = todays_date - F('datebuy'))\
.order_by('datebuy')
When I retrieve the data, i got this 3150 days, 20:08:00
.
How can I do to remove the time because I just want to display the number of days
?
I've tried:
device_record = Devc.objects.annotate(duration = (todays_date - F('datebuy')).days)\
.order_by('datebuy')
the error returned:
'F' object has no attribute 'days'
I define todays_date like this todays_date = datetime.now().date()
, the datebuy
is DateTimeField