'%d-%m-%Y' format for DateTimefield in django

6,740 views
Skip to first unread message

Jigar

unread,
Aug 28, 2009, 3:19:57 AM8/28/09
to Django users
Hi All,

I am trying to add the '%d-%m-%Y' format in DateTimefield. As django
does not support this format so when I add different date formats, it
gives "invalid date/time" error in django console.This error occurs
because the form is not valid(form.is_valid()) as above mentioned date
format is not supported by django. Also, I want to store this date in
the mysql database.

I have tried following:
I have converted the string (date entered in html page) in to the date
object which is in '%d-%m-%Y' in views.py before form_is_valid()
called. Now I am not able to set the attribute value for a particular
field so that form.is_valid() gets the correct date object.

Any Ideas for this issue ?

Karen Tracey

unread,
Aug 28, 2009, 9:10:15 AM8/28/09
to Django users
On Aug 28, 3:19 am, Jigar <jigar.vana...@gmail.com> wrote:
> Hi All,
>
> I am trying to add the '%d-%m-%Y' format in DateTimefield. As django
> does not support this format so when I add different date formats, it
> gives "invalid date/time" error in django console.This error occurs
> because the form is not valid(form.is_valid()) as above mentioned date
> format is not supported by django.

It is not correct to say that Django does not support that format.
That format is not one that is accepted by default as an input format
for the DateTimeField form field. However, you can easily specify
your own input_formats and then your form will accept that format:

http://docs.djangoproject.com/en/dev/ref/forms/fields/#datetimefield

> Also, I want to store this date in
> the mysql database.
>

It does not make sense to say you want to store that format in MySQL.
The value stored in MySQL is a DATETIME, independent of any particular
format. Since you are using Django you do not need to be concerned
with what format is used when Django stores the data to MySQL or
retrieves it from MySQL. What you need to adjust is the input formats
your field accepts, and the output format used by your form field's
widget to display existing data (see the format parameter here, for
example: http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.DateTimeInput)

Karen

zayatzz

unread,
Aug 31, 2009, 9:29:10 AM8/31/09
to Django users
Check out this thread, where Karen Throughly explained date formats
and widgets to me:

http://groups.google.com/group/django-users/browse_thread/thread/7488aa81bfa94cac/

Alan.
> example:http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms....)
>
> Karen
Reply all
Reply to author
Forward
0 new messages