iTunes 'Play Date' tag numeric mystery, solved!

Recently I embarked on a project that involved parsing the contents of my iTunes library file, which stores information about all the MP3 files in my collection, in an XML format.

What I wanted to do was assemble a list of songs I played, in chronological order. Fortunately, the file, "XML Music Library.xml" offers two tags that capture this info, namely:

<key>Play Date</key><integer>3365245919</integer>
&
<key>Play Date UTC</key><date>2010-08-21T18:31:59Z</date>
Setting aside Apple's odd notions of how XML works for a second, we can see that the date played is captured in a human readable format, in the latter "Play Date UTC" tag which of course must be parsed with a regular expression to compute against. (UTC stands for Coordinated Universal Time).

I was curious as to if I could calculate the time played directly from "Play Date" tag rather than parse it out from the "Play Date UTC" tag. I suspect that iTunes is storing this number for exactly such purposes, in fact. The challenge however, would be to decipher the number.

So, in the example above, the "Play Date" value of "3365245919" should equal "2010-08-21T18:31:59" stated in "Play Date UTC." I would just need to find the conversion algorithm.

My first guess was that it was a Unix Timestamp, given that iTunes, in its original Macintosh incarnation, runs on Unix. The Unix Timestamp counts time in terms of seconds elapsed since January 1, 1970. However, when I put the number "3365245919" into a Unix Timestamp calculator, I didn't get August 21, 2010 at all, but rather Aug 21, 2076!! Crazy!

My next step was to reverse engineer the "Play Date" number so to speak. By comparing a few "Play Date" and "Play Date UTC," I sussed that the incrementation was, in fact, in seconds.

For instance, one song played at 3:10 has "Play Date" of "3365248245" while the next song, played at 3:13, had a "Play Date" of "3365248408," which was greater by 163--or just under three minutes if you consider a second for each increment.

So, August 21, 2010, 6:31.59 was 3,365,245,919 seconds ahead of what date? Well, using this online Epoch Converter, 3,365,245,919 seconds equals 38,949 days (and 14 hours and 31 minutes).

So, now using this online date calculator (Isn't the Internet great?!), we find that subtracting 38,949 days from August 21, 2010 brings us to January 1, 1904.

So, in short, the iTunes "Play Date" figure is the number of seconds that have elapsed since January 1, 1904.

In other words, Apple is using an Epoch time, with January 1, 1904 as the starting point (Epoch time has no unified start point per se, just whatever the keeper of the timestamp decides it to be).

And this is keeping with an Apple tradition. According to this online Filemaker help file, this date is the official starting point for all Macintosh computer timestamps, as it was last century's "earliest New Year's Day that falls in a leap year"--an easy starting point for developers.



Back