Filter model by date today

Hello, I have a small question, is there a way to filter data at today’s date, knowing that the model concerned contains a field

    created_at = models.DateTimeField(
        auto_now_add=True, auto_now=False, null=True, blank=True)

Yes. See Time zones | Django documentation | Django

so I tried that, but the thing is that it filters by the second and I would like my data to stay 24 hours

.filter(created_at=now)

Please be more explicit as to what you’re looking for.

Are you looking for the entries that were added “today”? Does that mean “today” UTC or “today” local? Does that mean between “midnight” (either UTC or local) and “now”? Or does that mean anything after “midnight”? (Note: Just because you have auto_now_add=True, that doesn’t guarantee that that field wasn’t modified somewhere else. You can’t assume that you don’t have a created_at field in the future.) Or do you mean anything within the previous 24 hours?

As you can see, there are many different ways to interpret this.

It’s true, I’ll give you an example, let’s say I have an order that falls on 11/12/2022 at 12:30, I’d like the order to stay 24 hours, that means that on 12/12/2022 at 12:30 the order will no longer be in the filter

Then you want to do a date range comparison, where the earliest date is “now” - 24 hours (see timedelta for how to calculate that) and the latest date is “now”.