madu kp
madu kp

Reputation: 89

Error in date and time parsing in Django ["'Tue, 02 Jul 2019 08:11:45 +0530' value has an invalid format. in YYYY-MM-DD HH:MM[:ss[.uuu]][TZ] format."]

I am getting the rss feed as xml, and I am parsing , but date and time zone is throwing an error

My model field

x = models.DateTimeField(blank=True, null=True)

view.py

y = MyModel()
y.x = prasedJson.pubdate
y.save()

My xml date and time format from rss one of the feed

   <pubDate>Tue, 02 Jul 2019 16:43:41 +0530</pubDate>

Error is

["'Tue, 02 Jul 2019 08:11:45 +0530' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]

How can I save this date and time, either with +0530 or without +0530 format?

Upvotes: 0

Views: 131

Answers (1)

kostans3k
kostans3k

Reputation: 467

I would recommend you to use parser from python-dateutil library to parse date from string:

from dateutil import parser

parsed_date = parser.parse(prasedJson.pubdate)

y = MyModel()
y.x = parsed_date
y.save()

Upvotes: 1

Related Questions