# Datetime.ParseDate

**URL:** <https://forums.plex.tv/t/datetime-parsedate/61207>\
**Category:** Dev/API Corner\
**Tags:** other-dev\
**Created:** [March 22, 2014, 3:15pm UTC](https://forums.plex.tv/t/datetime-parsedate/61207 "2014-03-22T15:15:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [March 22, 2014, 3:15pm UTC](https://forums.plex.tv/t/datetime-parsedate/61207/1 "2014-03-22T15:15:01Z")

</div>

Dear all.

&nbsp;

I got a problem with the Datetime.ParseDate function

&nbsp;

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

&nbsp;

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?

&nbsp;

According to [https://dev.plexapp.com/docs/api/utilkit.html](https://dev.plexapp.com/docs/api/utilkit.html)

&nbsp;

"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."

&nbsp;

```
Datetime.ParseDate(date)

```
Attempts to convert the given string into a datetime object.
Return type:	datetime

```
```

So what am I missing here?

&nbsp;

/Tommy

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [March 22, 2014, 5:32pm UTC](https://forums.plex.tv/t/datetime-parsedate/61207/2 "2014-03-22T17:32:48Z")

</div>

Try:

```
test = Datetime.ParseDate(addedAt).date
```

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [March 22, 2014, 8:18pm UTC](https://forums.plex.tv/t/datetime-parsedate/61207/3 "2014-03-22T20:18:22Z")

</div>

> 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:

> &nbsp; File "/root/Library/Plex Media Server/Plug-ins/Plex2csv.bundle/Contents/Code/\_\_init\_\_.py", line 437, in scanMovieDBBasic  
> &nbsp;&nbsp;&nbsp; test = Datetime.ParseDate(addedAt).date  
> &nbsp; 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  
> &nbsp;&nbsp;&nbsp; result = dateutil.parser.parse(date)  
> &nbsp; File "/root/Library/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/dateutil/parser.py", line 700, in parse  
> &nbsp;&nbsp;&nbsp; return DEFAULTPARSER.parse(timestr, \*\*kwargs)  
> &nbsp; File "/root/Library/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Platforms/Shared/Libraries/dateutil/parser.py", line 309, in parse  
> &nbsp;&nbsp;&nbsp; ret = default.replace(\*\*repl)  
> ValueError: year is out of range  
> &nbsp;

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

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [March 22, 2014, 9:00pm UTC](https://forums.plex.tv/t/datetime-parsedate/61207/4 "2014-03-22T21:00:57Z")

</div>

Can you show me a sample string?

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [March 22, 2014, 9:04pm UTC](https://forums.plex.tv/t/datetime-parsedate/61207/5 "2014-03-22T21:04:06Z")

</div>

> \<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](http://myPMS:32400/library/sections/2/all)

/Tommy

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [March 22, 2014, 9:15pm UTC](https://forums.plex.tv/t/datetime-parsedate/61207/6 "2014-03-22T21:15:26Z")

</div>

Gotcha. Try Datetime.FromTimestamp()

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [March 22, 2014, 9:33pm UTC](https://forums.plex.tv/t/datetime-parsedate/61207/7 "2014-03-22T21:33:58Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 21, 2019, 1:39am UTC](https://forums.plex.tv/t/datetime-parsedate/61207/8 "2019-12-21T01:39:03Z")

</div>

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