1

in my settings.py settings, I have

from django.conf.global_settings import DATETIME_INPUT_FORMATS

DATETIME_INPUT_FORMATS += ('%Y-%m-%d %I:%M %p',)

But when I enter the date 2015-10-23 01:48 pm in my form that takes date time I get Enter a valid date/time..

The model is date_completed = models.DateTimeField(null=True, blank=True).

How can make the model take the format 2015-10-23 01:48 pm?

1
  • 2
    What is base.py? Did you mean to say settings.py? Oct 16, 2015 at 19:24

1 Answer 1

1

This is probably happening because you have set USE_L10N to True in your settings. From the documentation for DATETIME_INPUT_FORMATS:

When USE_L10N is True, the locale-dictated format has higher precedence and will be applied instead.

i.e., your carefully constructed setting will be ignored :).

Also, note that depending on your locale, %p expects different values - e.g., for en_US it expects capitalised AM and PM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.