Confusion around timedelta and strptime in templates

I’d appreciate some help with my general confusion around time stamps and manipulating times please.

I want to calculate the number of minutes between now and 23:30. There’s a good chance I’ve gone about this completely incorrectly. Here’s where I am so far - getting the desired future time as a date time.

{% set today =(now().date()) | string %} 
{% set endtime ='23:30:00' | string %}
        
{{
as_datetime(today +' '+ endtime)
}}

What I can’t figure out is how to calculate the number of minutes between now and then. I’ve messed around with strptime and timedelta but I’m just blindly flailing.

Any pointers please?

{{ (today_at("23:30")|as_timestamp - now()|as_timestamp) // 60 }}
1 Like

Along similar lines to @Troon, you can use the total_seconds() function on a timedelta:

{{ (today_at("23:30") - now()).total_seconds() // 60 }}

2 Likes

Fabulous, thanks @Troon and @Didgeridrew. I really appreciate it!