[Django]-How to do a query based on a subtraction result of two datetime objects in a Django query?

4👍

You can calculate the datetime for 24 hours ago and then do a gte query against that.

from datetime import datetime, timedelta

target_time = datetime.now() - timedelta(hours=24)
my_items = MyModel.objects.filter(obj_time__gte=target_time)

Leave a comment