# DateField localization in Templates

**URL:** <https://forum.djangoproject.com/t/datefield-localization-in-templates/2356>\
**Category:** Using Django\
**Created:** [May 10, 2020, 8:57am UTC](https://forum.djangoproject.com/t/datefield-localization-in-templates/2356 "2020-05-10T08:57:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaximilianKindshofer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/maximiliankindshofer/32/835_2.png) [@MaximilianKindshofer](https://forum.djangoproject.com/u/MaximilianKindshofer)\
**Post date:** [May 10, 2020, 8:57am UTC](https://forum.djangoproject.com/t/datefield-localization-in-templates/2356/1 "2020-05-10T08:57:01Z")

</div>

I am using a date input in my form template. It accepts a value in form of A [`DOMString`](https://developer.mozilla.org/en-US/docs/Web/API/DOMString) representing a date in YYYY-MM-DD format, or empty but Django gives me a value in dd.mm.yyyy due to localization.

Also I am using widget\_teaks in my form view to add some Attributes:

```
{% if field|field_type == 'datefield' %}
    {% render_field field|append_attr:"class:form-control dateField " type="date" %}
{% else %}

```

I tried to fix it in the template using jQuery but it returns just an empty string for the value:

```
$(document).ready(function(){
    var date = $(".dateField").val();
    console.log(date);
 });

```

So I can’t just update the value accordingly. I tried to unlocalize the whole template but still the date is formated in dd.mm.yyyy.

The relevant part of the settings:  
LANGUAGE\_CODE = “de”

```
TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True

```

and the relevant Field in the Model:

```
naechste = models.DateField(verbose_name="nächste Prüfung")

```

and the Form itself:

```
class Massnahmen_Form(forms.ModelForm):
    class Meta:
        model = Massnahmen
        exclude = ["version", "latest_version"]

```

Can you tell me what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 10, 2020, 10:36am UTC](https://forum.djangoproject.com/t/datefield-localization-in-templates/2356/2 "2020-05-10T10:36:24Z")

</div>

Clarify please. When you say “Django is giving me a value as did.mm.yyyy”, are you saying that existing data for that field is showing up in that format? Or are you saying that when the form is submitted, that’s how you’re seeing the date in your view?

---

<div class="post-metadata">

**Author:** ![MaximilianKindshofer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/maximiliankindshofer/32/835_2.png) [@MaximilianKindshofer](https://forum.djangoproject.com/u/MaximilianKindshofer)\
**Post date:** [May 10, 2020, 11:31am UTC](https://forum.djangoproject.com/t/datefield-localization-in-templates/2356/3 "2020-05-10T11:31:34Z")

</div>

Hi Ken,

It shows up in my UpdateView From. In the Template Field the value of value arg in the html input is in the dd.mm.yyyy format.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 10, 2020, 11:54am UTC](https://forum.djangoproject.com/t/datefield-localization-in-templates/2356/4 "2020-05-10T11:54:23Z")

</div>

Have you tried setting the [DATE\_FORMAT](https://docs.djangoproject.com/en/3.0/ref/settings/#date-format) and [DATE\_INPUT\_FORMATS](https://docs.djangoproject.com/en/3.0/ref/settings/#date-input-formats) settings?

(I haven’t tried this, this is just what I managed to find in the docs.)

(Note: Both point out that they are overridden if USE\_L10N is True, so you’d need to make sure that localize is off for that section of your template.)

Ken

---

<div class="post-metadata">

**Author:** ![MaximilianKindshofer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/maximiliankindshofer/32/835_2.png) [@MaximilianKindshofer](https://forum.djangoproject.com/u/MaximilianKindshofer)\
**Post date:** [May 10, 2020, 7:42pm UTC](https://forum.djangoproject.com/t/datefield-localization-in-templates/2356/5 "2020-05-10T19:42:31Z")

</div>

Setting L10N to False worked, Tanks Ken!
