Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the correct format for django dateTime?

Im writting an app, and im using a datetime selector to allow users to select a date and time. After some formatting in javascript, im left with a dateTime like this:

2012-09-04 06:00 PM

and django throws and error saying:

[u"'2012-09-04 06:00 PM' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]

Ive also tried

2012-09-04 06:00PM
2012-09-04 06:00 P.M.
2012-09-04 06:00P.M.

but no luck. Can anyone see what Im doing here? Or know what django is looking for (in English)?

like image 597
itcropper Avatar asked Sep 03 '12 23:09

itcropper


People also ask

How do I use datetime in django?

First, open the views.py file of your Django application and import the datetime module. Next, use the datetime. now() method to get the current date and time value. Now, we can either assign this method to a variable or we can directly use this method wherever we required the datetime value.

What is the format of datetime in Python?

format is the format – 'yyyy-mm-dd'

How do I get the current date in dd mm yyyy format in Python?

Use strftime() function of a datetime class For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.

What is the default format for datetime date type?

DateTime Data Type The dateTime is specified in the following form "YYYY-MM-DDThh:mm:ss" where: YYYY indicates the year. MM indicates the month. DD indicates the day.


Video Answer


1 Answers

As said by the error msg, it expects YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ], thus following are valid values:

2012-09-04 06:00
2012-09-04 06:00:00
2012-09-04 06:00:00.000000

# w/ optional TZ as timezone. 
2012-09-04 06:00Z # utc
2012-09-04 06:00:00+0800
2012-09-04 06:00:00.000000-08:00
like image 140
okm Avatar answered Sep 21 '22 03:09

okm