This is a part of my code to display the time elapsed since last last updated:
{{(as_timestamp(now())-as_timestamp(states.input_boolean.torktumlaren_running.last_updated)) | timestamp_custom(‘%H hours and %M minutes’, false) }}
But is it possible to remove leading zeros?
I have tried to add a hyphen, e.g. %-H but that doesn’t work.
I have also tried to implement .lstrip but how I try it won’t work.
Does someone know how to do this?
Or do someone has a better way to achieve this?
Thank you for your answer.
I tried the command and had to change position of some backets and then it removed the leading zeros.
But it also removes the trailing zeros.
For instance:
01h 10 min would be 1h 1min.
I have tried to change the command but with no luck.
Any idea?
I’m not sure why - doesn’t work. Just use this instead:
{% set h = as_timestamp(now()) | timestamp_custom('%H', false) |int %}
{% set m = as_timestamp(now()) | timestamp_custom('%M', false) |int%}
{{ h }} hours {{ m }} minutes
Same concept, just returns the actual numbers in the string instead of a number formatted as a string with leading zeros.
Just as_timestamp(now()) with whatever difference that you want.