Dinges28
(Richard)
September 18, 2020, 7:37am
1
Probably this is a really simpel one, but i cannot get it working.
I want a input_datetime to have a 30 minutes added to the current time, but want to round it to the next 5 or 0 minutes.
The template I have now:
{{ (now().strftime("%s") | int +(30*60)) | timestamp_custom("%H:%M") }}
This gives me a brilliant 30 minutes after now.
For example it is now 9:36, adding 30 minutes gives 10:01, but I want the result to be 10:00 or 10:05…
What to add to the template??
tom_l
September 18, 2020, 9:42am
2
Try this in the template editor:
{% set x = 33 %}
{{ x - ( x % 5 ) }}
x % y
returns the remainder of x/y
Not sure how to work that into your template. Maybe by converting the time to a timestamp (in seconds) doing the math as timestamp % 300
(since 300 seconds = 5 minutes) then converting back to a time.
Dinges28
(Richard)
September 18, 2020, 9:55am
3
I came up with this template:
{{ (now().strftime("%s") | int +(30*60) - ((now().strftime("%s")) | int ) % 300 ) | timestamp_custom("%H:%M:%S") }}
1 Like