Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can make my django datetime field to display seconds

I have a datetime field 'scantime' in my django model.

scandate = models.DateTimeField(max_length=100)

When I retrieve this from mysql database, it is displaying in my django UI like this: Oct. 16, 2014, 4:37 p.m.

But when I debug, this value is something like this: datetime.datetime(2014, 10, 13, 6, 8, 47, tzinfo = UTC).

Though seconds are stored in DB, django is not displaying seconds in the UI bydefault.

My template code is like this:

{% for key,value in logdata.items %} <tr> {% for item in value %} <td>{{ item }}</td> {% endfor %} </tr> {% endfor %}

Is there any way that I can display seconds in UI? Please help me

like image 551
Suresh Kota Avatar asked Sep 21 '25 09:09

Suresh Kota


1 Answers

Try like this,

 <td>{{ item|date:'Y-m-d H:i:s' }}</td>

Django documentation: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date

like image 115
Adem Öztaş Avatar answered Sep 22 '25 22:09

Adem Öztaş