Date formats and Django forms

Date formats are something that US dominance remains unable to overcome. Whilst all software assumes a format of mm/dd/yyyy, all other nations of the world want to change that to their local preference.

Django is no exception.

Here’s the magic incantation to make Django 1.1 output and input dates in an Australian format.


DATE_FORMAT = '%d/%m/%Y'
...
class ProfileForm(forms.ModelForm):
    ...
    date_of_birth = forms.DateField()
    date_of_birth.widget = forms.DateInput(format=DATE_FORMAT)
    date_of_birth.input_formats = (DATE_FORMAT,)
This entry was posted in geek and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>