Date formatting with helper template calculations

Hi All,
Hopefully an easy one for someone but its doing my head in! I’m trying to calculate the date at which my solar battery system will exceed the warrantied throughput period.
I’ve got the calculations to work but I’m trying to get the date to display as dd-mm-yyyy but its fighting back.
My template sensor code is;

{{ (states('input_datetime.fox_commissioning_date') | as_datetime | as_local 
+ timedelta(days= (states('sensor.fox_days_to_exceed_warranty_throughput')) | int(0))) }}

The output displays as;
2031-01-26 00:00:00+00:00
I’ve tried lots of combinations of .strftime(‘%d.%m %Y’) or timestamp_custom('%d %m %Y) but just get errors.
Could anyone point me to the correct syntax?
Thanks,
Colin

You were probably just using the method or filter at the wrong depth of parentheses… I tend to find using Jinja variables more readable than nesting a bunch of parentheses. Since your template is using datetime objects, let’s stick to datetime methods and use strftime():

{% set start_dt = states('input_datetime.fox_commissioning_date') | as_datetime | as_local %}
{% set offset = states('sensor.fox_days_to_exceed_warranty_throughput') | int(0) %}
{{ (start_dt + timedelta(days=offset)).strftime('%d-%m-%Y') }}
1 Like

Thank you - thats sorted it, now displays correctly.
Was pretty sure that it was something daft in the syntax / placement but had gone round so many times I was going screen blind.