Template for counting down days to a specific date?

I’m looking to create a Markup card that uses a template to show a countdown to a specific date in days.

I’ve searched the forums and so far have

{{ as_timestamp("2026-01-31") - (as_timestamp(now()) ) | timestamp_custom("%j") | int }}

but that gives me a result of “1769835577” which I’m assuming is in seconds. I looked at timestamp_custom but didn’t see a way to convert seconds to days or years / months / days.

Any assistance appreciated. Thanks!

{{ ('2026-01-31' | as_datetime | as_local - now()).days }}

The template reports 372.

Wow, that’s elegant. Thanks!

With the tip about as_datetime, I’ve found and saved https://www.reddit.com/r/homeassistant/comments/1b7ntve/date_time_a_guide_i_made_for_formatting/ to help me with future time and date work I do in HA.

1 Like

That’s a pretty good tutorial but it does a few things the hard way (and overlooks using a few existing functions).

For example, if I need a datetime object representing today’s date at 08:30, I would use the today_at() function like this: today_at('08:30') (as opposed to using now() and the replace method).

There are also time_until() and time_since() functions for computing duration.

Templating - Time

In addition, when working with datetime and timedelta objects it’s helpful to know their inherent properties and methods.

Python - Datetime