Filter a field with timestamp (datetime) to get rows that does not contain today's date in Django

Viewed 29

I have a Django model with a timestamp field. I want to filter and get the number of rows that does not contain today's date. The timestamp field contains the date, time, and time zone.

I understand that to get rows with today's date, we do the following:

tablename.objects.filter(timestamp__date=date.today()).count()

Thank you.

1 Answers

.exclude returns the inverse of .filter, so it would be

tablename.objects.exclude(timestamp__date=date.today()).count()

Django docs

Related