1

In the form I've date field in the MM/DD/YYYY format it works well when the language is set to english when another locale selected it becomes unable to create record in the database due to the incorrect date format error. The date is manually selected from the user interface.

Is there any issues on this problem, may be someone already faced such a problem?

Sultan

sultan
  • 5,978
  • 14
  • 59
  • 103

2 Answers2

1

When the form is submitted, text from the field is converted to python type. In our scenario, it is datetime.datetime.

When the USE_L10N setting is enabled (it is by default), django uses locale-specific formats during conversion. And here is the root cause of the problem: Format "MM/DD/YYYY" is not available on selected locale.

If you want to use just the mentioned manual datetime format, the correct solution would be to update the form field to accept that format. E.g.

valid_from = forms.DateField(
    input_formats=['%m/%d/%Y']
)
Peter Svac
  • 302
  • 4
  • 4
0

Before you insert your value into the database use "strftime".

How to print date in a regular format in Python?

Community
  • 1
  • 1
StefanNch
  • 2,569
  • 24
  • 31
  • I changed the date format in JQuery datepicker widget and it worked, `$( ".published" ).datepicker({ dateFormat: 'yy-mm-dd' });` – sultan Dec 05 '11 at 15:48