[Django]-Django-models Change format of dateField as "DD-MM-YYY"

1👍

You need just to override Django’s defaults locale settings. Add this to your settings.py file

from django.conf.locale.es import formats as es_formats

es_formats.DATETIME_FORMAT = "d M Y H:i:s"

1👍

fahim kazi was right: to define a models.DateField format, you need DATE_FORMAT, not DATETIME_FORMAT.

Yet Naveen Varshney was also right: not DATE_FORMAT nor DATETIME_FORMAT work without specifying the language, with es_formats for instance.

Therefore, from the combination of both answers, put the following in settings:

es_formats.DATE_FORMAT = 'd-m-y'

(Also '%d-%m-%y' printed %01-%08-%20 thus the % is not needed).

Thanks both.

0👍

add this to your settings.py

DATE_FORMAT = '%d-%m-%y'

for more check this date format

Leave a comment