I have below code which outputs datetime values as shown below:
available_hours = [hour for hour in hours_between if hour not in reserved_times]
print(available_hours)
[datetime.datetime(2021, 12, 8, 12, 0), datetime.datetime(2021, 12, 8, 13, 0), datetime.datetime(2021, 12, 8, 14, 0), datetime.datetime(2021, 12, 8, 16, 0), datetime.datetime(2021, 12, 8, 17, 0), datetime.datetime(2021, 12, 8, 18, 0), datetime.datetime(2021, 12, 8, 19, 0), datetime.datetime(2021, 12, 8, 20, 0), datetime.datetime(2021, 12, 8, 21, 0)]
I render them in the template like:
{{ available_hours }}
and i got all above datetime values.
How can i change the format so i can show them like Mon 12 2021, 21:00?
Thank you
CodePudding user response:
try this
<p>
available hours:
{% for my_time in available_hours %}
{{ my_time|date:"M d Y, H:i" }}
{% endfor %}
</p>