-1

I am trying to subtract the lunch time if it is greater than 12 but got this error "TypeError: '>' not supported between instances of 'str' and 'int'". How can I convert the lunch time to integer in jinja template: lunch time returns 14:34 as a string

        {% if  today.lunch_time[:2] >12 %}
            <p>Lunch Time : {{ today.lunch_time[:2] - 12}} PM</p>
        {% else %}
            <p>Lunch Time : {{ today.lunch_time}} AM</p>
        {% endif %}

1 Answers1

2

You can convert string to integer by '|int'.

Solution:

{% if  today.lunch_time[:2]|int >12 %}
    <p>Lunch Time : {{ today.lunch_time[:2]|int - 12}} PM</p>
{% else %}
    <p>Lunch Time : {{ today.lunch_time}} AM</p>
{% endif %}