Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Problem with DateField input_formats [RSS Feed]

#1 June 23, 2010 16:34:20

b.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with DateField input_formats


I have:

DATE_INPUT_FORMATS = (
'%n/%j/%Y', '%n/%j/%y', # '10/25/2006', '10/25/06'
'%n-%j-%Y', '%n-%j-%y', # '10-25-2006', '10-25-06'
'%M %j %Y', '%M %j, %Y', # 'Oct 25 2006', 'Oct 25, 2006'
'%b %j %Y', '%b %j, %Y', # 'oct 25 2006', 'oct 25, 2006'
'%F %j %Y', '%F %j, %Y', # 'October 25 2006', 'October 25, 2006'
)


class CandidateProfileForm(forms.ModelForm):
class Meta:
model = Person
dob = forms.DateField(input_formats=DATE_INPUT_FORMATS)


But I'm not getting my date format through. For example, 4-20-1990
fails, even though I think it should be covered by %n-%j-%Y

I've also tried:
class CandidateProfileForm(forms.ModelForm):
class Meta:
model = Person
widgets = {
'dob':
forms.DateField(input_formats=DATE_INPUT_FORMATS),
}

with no luck. What am I missing here?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 23, 2010 16:54:41

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Problem with DateField input_formats


On Wed, Jun 23, 2010 at 11:34 AM, bax...@gretschpages.com <
mail.bax...@gmail.com> wrote:

> I have:
>
> DATE_INPUT_FORMATS = (
> '%n/%j/%Y', '%n/%j/%y', # '10/25/2006', '10/25/06'
> '%n-%j-%Y', '%n-%j-%y', # '10-25-2006', '10-25-06'
> '%M %j %Y', '%M %j, %Y', # 'Oct 25 2006', 'Oct 25, 2006'
> '%b %j %Y', '%b %j, %Y', # 'oct 25 2006', 'oct 25, 2006'
> '%F %j %Y', '%F %j, %Y', # 'October 25 2006', 'October 25, 2006'
> )
>
>
Looks like you are using the table fromhttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#ttag-now, which
is used for formatting date/times for output. The input formats, as notedhttp://docs.djangoproject.com/en/dev/ref/settings/#date-input-formatsuse
Python's formatting characters:http://docs.python.org/library/datetime.html#strftime-strptime-behavior, not
the ones in that other table which come from PHP's date() function (yes,
this is not ideal that the two are different, but that's the way it is).

%n is not in Python's table -- I think you want %m where you have %n

%j, to Python, is day of the year as a decimal number, not day of the month.
I think you want %d where you have %j

%M is minutes, I think you want %b where you have %M

%F is not in the table, I think you want %B where you have %F.

Karen
--http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Problem with DateField input_formats [RSS Feed]

Board footer

Moderator control

Enjoy the 19th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support