Reputation: 163
I currently have a table which is displaying on a HTML page, data which has been inputted into from a form. I think the format for the data in MySQL table saves as yyyy-mm-dd. I would like the date that is displayed on the table to be in the format DD-MM-YYYY.
I have tried looking at previous questions but cannot find a solution for this.
Below is a snippet of my code for the HTML table which pulls information from some of my model tables.
<tr>
<td>
{{ current_user.first_name }} {{ current_user.last_name }}
</td>
<td>
{% if current_user.tasterday %}
{{ current_user.tasterday.date }}
{% else %}
-
{% endif %}
</td>
<td>
{% if current_user.course %}
{{ current_user.course.name }}
{% else %}
-
{% endif %}
</td>
<td>
{% if current_user.tasterday %}
{{ current_user.tasterday.description }}
{% else %}
-
{% endif %}
</td>
</tr>
Could someone please tell me what I need to add to the date section so that the format is DD-MM-YYY. Thankyou.
Upvotes: 0
Views: 604
Reputation: 1744
You can format your Date
Object using strftime
in jinja2.
{{ current_user.tasterday.date.strftime('%d-%m-%Y') }}
If you want to change the format this is a good resource.
Upvotes: 1
Reputation: 51
I think this python script should help. It displays current time in dd/mm/yyyy,you can adapt it for your project. Also consider changing the way the date is stored in the db from your database structure.
import datetime
x = datetime.datetime.now()
print(x.strftime("%x"))
Upvotes: 0