Home > front end >  date formatting datefield in django
date formatting datefield in django

Time:12-22

I want to have the given format "dd/mm/yyyy" overall the application, but momentally I have "mm/dd/yyyy".

Here's the code in models.py

period_from = models.DateField(db_column="Period From", blank=True, null=True)

How to define it for all the datefields and in which file?

CodePudding user response:

You can use the DATE_FORMAT [Django-doc] and SHORT_DATE_FORMAT settings [Django-doc] to specify how Django will format date objects.

Note that if you enable USE_L10N [Django-doc], then these settings will not have effect, and Django will format the date according to the locale of the user.

  • Related