[Answer]-Display hour with 15 min interval in django template

1πŸ‘

βœ…

I don’t think this is possible only with the templating language unless you write a custom tag for this.
But this can be easily achieved with 3 lines of python in your view:

times = []
for i in range(0, 24*4):
  times.append((datetime.combine(date.today(), time()) + datetime.timedelta(minutes=15) * i).time().strftime("%I:%M %p"))

in your template:

{% for time in times %}
    <option>{{ time }}</option>
{% endfor %}
πŸ‘€Ponytech

Leave a comment