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)?
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.
format is the format – 'yyyy-mm-dd'
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With