Displaying dates with templates

I’m sure this is simple but I’m obviously not searching for the right information. I have an entity with an attribute which is a date string. I’d like to display it as ddmmyy.

I’ve tried numerous things, this being the last:

{{ strptime(state_attr(‘sensor.bin_collections’, ‘lastUpdate’),“%d%m%y”) }}

It just gives me 2019-09-28T06:26:11+00:00 which is the original value of the attribute. What am I doing wrong?

Try:

{{ as_timestamp(state_attr('sensor.bin_collections', 'lastUpdate')) | timestamp_custom('%d%m%y', True) }}

Or this:

{{ state_attr('sensor.bin_collections', 'lastUpdate').strftime('%d%m%y') }}

The first one will be in local time, the second will be in UTC (I think).

1 Like

Thanks, the 1st one was exactly what I was looking for.

1 Like