Datetime.ParseDate

Dear all.

 

I got a problem with the Datetime.ParseDate function

 

I'm extracting the addedAt value of a movie, and get a string back okay

 

I then use the code below:

test = Datetime.ParseDate(addedAt)

print test.strftime(’%m/%d/%Y’)

And get back, that Year is out of range?

 

According to https://dev.plexapp.com/docs/api/utilkit.html

 

"The Datetime API provides a number of methods for manipulating Python datetime objects and converting them to and from other formats like timestamps or string representations."

 

 Datetime.ParseDate(date)
Attempts to convert the given string into a datetime object.
Return type:	datetime

So what am I missing here?

 

/Tommy

Try:

test = Datetime.ParseDate(addedAt).date

Try:

test = Datetime.ParseDate(addedAt).date

Tried it, but sadly no good here :(

My code:

		for myMedia in myMedias:
			addedAt = myMedia.get('addedAt')
			test = Datetime.ParseDate(addedAt).date
			print test.strftime('%m/%d/%Y')

Output from debug log:

  File "/root/Library/Plex Media Server/Plug-ins/Plex2csv.bundle/Contents/Code/__init__.py", line 437, in scanMovieDBBasic
    test = Datetime.ParseDate(addedAt).date
  File "/share/MD0_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/api/utilkit.py", line 376, in ParseDate
    result = dateutil.parser.parse(date)
  File "/root/Library/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/dateutil/parser.py", line 700, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/root/Library/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/dateutil/parser.py", line 309, in parse
    ret = default.replace(**repl)
ValueError: year is out of range
 

Which leads me to a "simple" Q:

What's behind the number?

I guessed it was either Unix TmeStamp or millisec. since Barkley's birth?

Problem is though, that I don't know how old Barkley is :D

/T

Can you show me a sample string?

<Video ratingKey="3" key="/library/metadata/3" studio="Warner Bros. Entertainment" type="movie" title="Charlie and the Chocolate Factory" originalTitle="Charlie and the Chocolate Factory" contentRating="PG" summary="En ung dreng vinder en turné gennem den mest fantastiske chokolade fabrik i verden, ledet af verdens mest usædvanlige slik fabrikant" rating="5.8000001907348597" year="2005" tagline="Veruca Is a very bad nut" thumb="/library/metadata/3/thumb/1393433793" art="/library/metadata/3/art/1393433793" duration="6896977" originallyAvailableAt="2005-07-10" addedAt="1393433761" updatedAt="1393433793">

got it from sending the following url:

http://myPMS:32400/library/sections/2/all

/Tommy

Gotcha. Try Datetime.FromTimestamp()

Gotcha. Try Datetime.FromTimestamp()

Almost perfect there.

Already went down that road, but didn't work, so when you now insisted, I tried it again, but needed to cast as float:

for myMedia in myMedias:
			addedAt = float(myMedia.get('addedAt'))
			test = Datetime.ParseDate(addedAt).date
			print test.strftime('%m/%d/%Y')

That got it working.

Huge thanks for all the hints and support

/T

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.