0

I am trying to post an entry into my Django model which has a DateTimeField. Since i am using angular on my frontend, the date format that it posts to my Django View is of the format

Tue Jun 30 2015 00:00:00 GMT-0500 (CDT) 

But Django will not allow me to post as the datetime format did not allow this format.

2015-05-23 18:48:08.543655

and it threw me this error:

[u"'Tue Jun 30 2015 00:00:00 GMT-0500 (CDT)' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]

So what do i use to get around this issue?

Abhishek
  • 2,998
  • 9
  • 42
  • 93
  • probably duplicate http://stackoverflow.com/questions/79797/how-do-i-convert-local-time-to-utc-in-python – MaNKuR May 23 '15 at 19:35
  • @MaNKuR this is not a duplicate because the post you referred to is UTC time which is supported using Datetime wheras CDT is not. – Abhishek May 24 '15 at 04:03

2 Answers2

2

Call toUTCString() on your Date instance:

var d = new Date();
var n = d.toUTCString();

On the python side thats parsable with:

datetime.strptime("Tue, 22 Nov 2011 06:00:00 GMT", "%a, %d %b %Y %H:%M:%S %Z")

Also if you're working with django forms, have a look at the datetimefield documentation. You can find an explanation on how to set various formats there.

Sebastian Wozny
  • 16,943
  • 7
  • 52
  • 69
0

In your view, just manipulate the date given by your angular code into the proper Django datetime format.

mcastle
  • 2,882
  • 3
  • 25
  • 43