82
Something like this would work for you:
from datetime import datetime, timedelta
how_many_days = 30
MyObject.objects.filter(entered__lte=datetime.now()-timedelta(days=how_many_days))
21
we can use Django timezone.now() with timedelta
from datetime import timedelta
from django.utils import timezone
time_threshold = timezone.now() - timedelta(days=7)
Entry.objects.filter(entered__gte=time_threshold)
- [Django]-How to make a POST simple JSON using Django REST Framework? CSRF token missing or incorrect
- [Django]-Convert seconds to hh:mm:ss in Python
- [Django]-Is APITest with Query params different then just normal url?
- [Django]-How do I start up remote debugging with PyCharm?
- [Django]-How to get primary keys of objects created using django bulk_create
- [Django]-Django: return string from view
Source:stackexchange.com