Input_formats to DateTimeField

14,053

Solution 1

Write the definition like this:

start_time=forms.DateTimeField(input_formats=['%Y-%m-%d %H:%M'])

Note that input_formats is a list and the Y is upper case. That should work.

Solution 2

Just did some trial and error. When specifying input_formats you have to consider that for a widget format='whatevers in here' is a string whereas input_formats=['whatevers in here', 'whatever else'] is a list.

Share:
14,053
hln
Author by

hln

Updated on July 31, 2022

Comments

  • hln
    hln almost 2 years

    I have a DateTimeField :

     start_time=forms.DateTimeField(input_formats='%y-%m-%d %H:%M')
    

    and in html

       {{form.start_time}}
    

    but no matter what i entre in th field, like: 2013-07-07 19:00 it will always give me an error : enter valid date/time, what is worng here? Thanks in Advance

  • Ryan G
    Ryan G almost 11 years
    what version of django are you guys using? I'm using 1.5.1 and am unable to use the input_formats argument.