Wednesday, June 23, 2010

Re: Problem with DateField input_formats

On Wed, Jun 23, 2010 at 11:34 AM, baxter@gretschpages.com <mail.baxter@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 from http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ttag-now, which is used for formatting date/times for output. The input formats, as noted http://docs.djangoproject.com/en/dev/ref/settings/#date-input-formats use 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-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment