Changing Date Added in iTunes

    Users of iTunes will be aware that you cannot change the date added field, it is not editable.  It cannot be changed via scripts as the property is read only.  This means that when re-adding or updating tracks in iTunes the date added will be set to the current time, even if the track/album has been in your collection for years.  Probably doesn’t bother the average user, but music collectors who like to keep track of when they acquired music find it annoying.

    The standard advice is to change the system time on your PC to the date/time you want and then add tracks or playlist.  However, this can have unintended consequences to other applications.  However, there is another option.

    RunasDate by Nirsoft allows you to run iTunes alone with a different date time from the system date.

    Put the path to iTunes into the Application to Run field.  Enter the date and time you want, although you can enter an adjustment to current system time.  Checking Move the Time forward…  makes the time tick forward in step with real time.  Check Immediate Mode and click Run.  iTunes will open normally, but any operations such as adding files/folders/playlists will be logged with the date and time set in RunasDate.  In the example above anything added to iTunes will appear to be added as of 05/07/2014 at 12:46 until you close iTunes.

    This is OK for adding a few files/folders backdated, but is laborious for more extensive work such as reimporting many tracks covering several periods.  iTunes can come to the rescue in that it will take a command line parameter of a file or playlist.  Put the path to an M3U playlist in the parameters field and iTunes will launch and import all the tracks in that playlist as if entered on the date set in RunasDate.

    For even more extensive importing and updating you will need to use scripting.  RunasDate supports command line so it can be scripted to run and launch iTunes with playlists to be imported and the date of import.

    So using VB.Net the following code will launch iTunes with the desired date/time and import the designated playlist.

    Process.Start([Path to RunasDate]\RunAsDate.exe", "/immediate 23/07/2013 16:32:23 ""C:\Program Files\iTunes\iTunes.exe"" ""[Path to Playlist]\Addlist.m3u""")

    Note, you need the version of RunasDate to match iTunes – so if iTunes is running in 64bit, you need the 64bit RunasDate.  Note also that the references to iTunes and the Playlist need to be double quoted.

    If you have a text file with references to playlist files and the dates required you could read that file into a datatable and then step through it to add each playlist with the desired date (substitute the date and time in the command with a value from a datatable or imported list).  I was able to import 5000 tracks with desired dates spanning a 7 year period in a couple of hours.

    Note:  If a track with the same path to the file to be imported is already in iTunes it will not be imported again.  The tracks have to be deleted first (gulp! – make a backup).  As you are winding the clock back in iTunes, you will get messages that your iCloud login has expired, and you may also get that it cannot access the iTunes store.  Logging out of your account in iTunes is advisable to stop the messages and unintended consequences.

    I found once or twice that iTunes would spontaneously create a new library and import the playlist into that.  You just need to close iTunes and restart it holding the Shift key down until you see the “Choose Library” dialog and select the original one.  This will not reinstate rating, and play history.  You will either have to live with that, or make a backup beforehand of the iTunes library xml file, and use a script to read that and reapply play history and rating.

    So not entirely straightforward, but easier and safer than changing the system date on your PC by hand.

    A function to change dates added in iTunes using VB.Net could look like:

    1) Get a reference to iTunes by means of the iTunesLib code library (in Visual Studio add the relevant COM library as a reference)

    iTunes = New iTunesLib.iTunesApp

    2) Initialise variables 

    Dim Row As DataRow

    Dim i As Integer

    Dim SelectedTracks as As iTunesLib.IITTrackCollection

    Dim T as iTunesLib.IITTrack

    3) Form to capture desired date

    Dim MyDate As New DateAdded


    Dim TheDate As New Date

    TheDate = MyDate.PickDate.SelectedDate.Value

    4) Get selected tracks from iTunes

    SelectedTracks = iTunes.SelectedTracks

    5) Loop through and read track data into datatable called Tracks.  Length of track in seconds is needed for an M3U playlist.  The current time is added to the selected date.  As the meta data from each track is read the track itself is deleted from iTunes (remember to make a backup).  Note iTunes collection indexes are 1 based not 0 based.

    For i = SelectedTracks.Count To 1 Step -1

    T = SelectedTracks.Item(i)

    Row = Tracks.NewRow

    Row("Track") = T.Name

    Row("Album") = T.Album

    Row("Artist") = T.Artist

    Row("Genre") = T.Genre

    Row("Rating") = T.Rating

    Row("LastPlayed") = T.PlayedDate

    Row("Plays") = T.PlayedCount

    Row("DateAdded") = TheDate.AddHours(Now.Hour).AddMinutes(Now.Minute)

    Row("Length") = (Convert.ToDateTime(T.Time).Hour * 60 * 60 + Convert.ToDateTime(T.Time).Minute * 60 + Convert.ToDateTime(T.Time).Second)

    Row("Path") = T.Location




    6) Close iTunes


    7) Create M3U playlist

    Dim TempPath As String = "C:\Temp\"

    Using writer As New StreamWriter(TempPath & "Addlist.m3u", False)


    For Each Row In Tracks.Rows

    writer.WriteLine("#EXTINF:" & Row("Length") & "," & Row("Artist") & " - " & Row("Track"))





    End Using

    8) Launch RunasDate to open iTunes with the desired date, passing in the required date and the path to the playlist created above

    Process.Start("[Path to RunasDate]\RunAsDate.exe", "/immediate " & TheDate & " ""C:\Program Files\iTunes\iTunes.exe"" """ & TempPath & "Addlist.m3u""")

    9) Pause execution to give iTunes time to launch and import playlist – otherwise playlist doesn’t get imported

     MessageBox.Show("Pause while iTunes loads")

    10) Get a new reference to iTunes as old is now broken, and select playlist just added

    iTunes = New iTunesLib.iTunesApp

    SelectedTracks = iTunes.LibrarySource.Playlists.ItemByName("Addlist").Tracks

    11) Create dataview to filter track data

    Dim TV as New DataView(Tracks)

    12) Loop through tracks in playlist and find matching meta data by filtering dataview by track, album and artist (assuming these do not duplicate)

    For i = 1 To SelectedTracks.Count

    T = SelectedTracks.Item(i)

    TV.RowFilter = "Track='" & Replace(T.Name,"'","''") & "' AND Artist ='" & Replace(T.Artist,"'","''") & "' AND Album = '" & Replace(T.Album,"'","''") & "'"

    If TV.Count > 0 Then

    T.Genre = TV(0)("Genre")

    T.PlayedDate = TV(0)("LastPlayed")

    T.PlayedCount = TV(0)("Plays")

    T.Rating = TV(0)("Rating")

    End If


    13)  Close iTunes to reset date back to system time


    Use at your own risk, and make that backup!  I take no responsibility if you trash your music.