Template - Date Configuration

Hi all, I am attempting to use a template sensor that will be set to true if a date (from another sensor) is within 1 day of the current date.

I am using a custom integration that will pull in my garbage collection schedule, but it gives me 2 sensors (one for garbage, one for recycling) that are just hard coded dates. For example, the sensor.garbage = December 30, 2024 at 12:00 AM.

In my template, I am getting the sensor date as a useable value by doing this:
{% set dt = states('sensor.garbage') | as_datetime | as_local %}

I am then calculating if that date is within 24 hours of the current date like this:
{{ now() - dt >= timedelta(hours=24) }}

This partially works. It gets set to true on my garbage collection day. I am trying to get it set to true 24 hours before my collection day (so I can use it as a reminder to take out the garbage cans).

Does anyone have any ideas how I can refactor this template sensor to show as true when it is 24 hours before my collection date?

Thanks!

True 24 hours before dt:

{{ now() >= dt - timedelta(hours=24) }}

Thanks for the reply. Looks like my ordering was off, so I appreciate the fix!

I ended up going with your solution and an added check to see if the date was the current day as well (so it is true if the day is 24 hours before and the current day).
{{ now() == dt or now() >= (dt - timedelta(hours=24)) }}