Template Sensor issue?

Hi,

So I have this code:

{{  ('2025-05-06' | as_datetime | as_local - now()).days }}

This outputs 9 days. On both my system in the UK and my boyfriends system in Germany.

By my calculations this would make the day we are interested in -1 days not 0 days. Am I going mad? Is there a bug?

EDIT:
Indeed this code:

{% set d =  ('2025-04-27' | as_datetime | as_local - now()).days %}
{{ d }}

outputs 0 days, which is clearly wrong, because it’s tomorrow not today.

This template:

{{ '2025-04-27' | as_datetime | as_local }}

produces this value (in my timezone):

2025-04-27 00:00:00-04:00

Notice the time is 00:00:00.

In contrast, now() will produce a value containing the current time. The time difference between tomorrow at 00:00:00 and today (at any time after 00:00:00 today) is less than a full day. That’s why it reports 0 days.

This reports 1 day because today_at() produces today’s date at 00:00:00.

{% set d =  ('2025-04-27' | as_datetime | as_local - today_at()).days %}
{{ d }}

So the solution is to use +1 which is what I am doing as the workaround.

{{  ('2025-05-06' | as_datetime | as_local - now()).days +1 }}

Oh I see, yes, using today_at() is the solution.