Python Flask and Jinja2 – How to get name of the day from date?

I'm trying to display a name of the day from the date string in Jinja2.

Example of what I want to achieve: From this string: '18-10-2020' - I would get 'Sunday'.

I am looking for a solution that would not require me to pass the name of the day from Python to Jinja2, but I would like to get the name of the day completely within Jinja2.

So far, I have the following code in my Jinja2 template:

{% for date in list_of_dates %}
    {% set rok, mesiac, den = date[2].split('-') %}
        {{ datetime.datetime.date(rok, mesiac, den).strftime("%A") }}
{% endfor %}

This code, however, returns a Jinja2 Exception error saying this: 'datetime' is undefined. I have datetime imported in my Python code.

Any ideas how can I fix this, please?

Thank you



Read more here: https://stackoverflow.com/questions/64413343/python-flask-and-jinja2-how-to-get-name-of-the-day-from-date

Content Attribution

This content was originally published by rogaloo at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: