Remove decimals from resulting datetime

I’m trying to calculate the time since something happened. When I use the following template:

{% set t = now() - (strptime( state_attr('sensor.blah_blah', 'start'), '%Y-%m-%dT%H:%M:%S%z')) %}
{{ t }}

The result is something like: 3:09:00.491679

I have tried piping to timestamp_custom(’%H:%M’) and I get an invalid input error. I’m kind of at a loss for how to remove the decimal and everything after it. It would look a whole lot cleaner in the UI if I could.

{% set t = now() - (strptime( state_attr('sensor.blah_blah', 'start'), '%Y-%m-%dT%H:%M:%S%z')) %}
{{ t.total_seconds() | timestamp_custom('%H:%M', false) }}
2 Likes

You are my hero! I’ve been at this for about an hour and just cant quite get it. This worked perfectly!! Thank you!

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.