Thursday, July 3, 2008

Formatting Dates with Django

Simply letting a date field be displayed with django results in something like this;
2008-07-03 09:20:12.019000
Which is quite helpful in the scientific world but it doesn't really add much to a lot of applications other than confusion.
The way to handle dates is to pass them through something of a filter like this;
{{ datefield|date:"d M Y" }} and the output is : 03 Jul 2008

The filter list can be found in the Django documentation;
http://www.djangoproject.com/documentation/templates/#now

The is also a somewhat useful entry I found here on the topic;
http://www.magpiebrain.com/blog/2005/08/21/formatting-dates-with-django/

No comments: