Change the addedAt date?

@leelynds Thanks for staying on this thread. I appreciate your efforts.

I ended up fixing this by directly setting the date in the database. For anyone that wishes to do the same, here is how I did it.

First I made a backup of the database file just in case this goes horribly wrong. To be completely safe, you could shutdown your Plex Media Server application first but it should be just fine to make these changes with it running. SQLite’s locking system is designed to handle concurrent processes accessing the database file, and we are making very small changes to a single table. But perhaps don’t do this during the Plex maintenance window. :wink:

# cd "/volume1/Plex/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"
# cp com.plexapp.plugins.library.db{,.bak}

Next was to run an SQL query to make sure it will be adjusting only the movies I want to change. In this case, I want to set the dates for the Star Wars movies in my library.

# sqlite3 com.plexapp.plugins.library.db "SELECT title,originally_available_at,added_at FROM metadata_items WHERE title LIKE 'star wars%';"
Star Wars IV: A New Hope|1977-05-25 00:00:00|2016-12-15 11:08:59
Star Wars V: The Empire Strikes Back|1980-06-20 00:00:00|2016-12-15 11:09:33
Star Wars VI: Return of the Jedi|1983-05-25 00:00:00|2016-12-15 11:10:02
Star Wars VII: The Force Awakens|2015-12-14 00:00:00|2016-12-15 11:11:14

The query is properly returning the 4 Star Wars movies. The originally_available_at field is the “Release Date” and added_at field is the “Date Added”. As you can see, the Date Added for these are a couple of weeks ago.

Now to run the SQL command to set the Date Added to be the same as the Release Date.

# sqlite3 com.plexapp.plugins.library.db "SELECT 'UPDATE metadata_items SET added_at=''' || originally_available_at || ''' WHERE id=''' || id || ''';' FROM metadata_items WHERE title LIKE 'star wars%';" | sqlite3 com.plexapp.plugins.library.db

Run the SQL query again and now the Date Added is set properly.

# sqlite3 com.plexapp.plugins.library.db "SELECT title,originally_available_at,added_at FROM metadata_items WHERE title LIKE 'star wars%';"
Star Wars IV: A New Hope|1977-05-25 00:00:00|1977-05-25 00:00:00
Star Wars V: The Empire Strikes Back|1980-06-20 00:00:00|1980-06-20 00:00:00
Star Wars VI: Return of the Jedi|1983-05-25 00:00:00|1983-05-25 00:00:00
Star Wars VII: The Force Awakens|2015-12-14 00:00:00|2015-12-14 00:00:00

Perfect! Here is how it appears in Plex

Kinda awesome to see movies added into Plex “40 years ago”

Now, if you want to change a single entry instead of using a wildcard query, you can use the id field in the commands like so.

Query to get the ID for all Star Wars entries.

# sqlite3 com.plexapp.plugins.library.db "SELECT id,title,originally_available_at,added_at FROM metadata_items WHERE title LIKE 'star wars%';"
58372|Star Wars IV: A New Hope|1977-05-25 00:00:00|2016-12-15 11:08:59
58373|Star Wars V: The Empire Strikes Back|1980-06-20 00:00:00|2016-12-15 11:09:33
58374|Star Wars VI: Return of the Jedi|1983-05-25 00:00:00|2016-12-15 11:10:02
58375|Star Wars VII: The Force Awakens|2015-12-14 00:00:00|2016-12-15 11:11:14

Change the 2nd WHERE clause in the command (WHERE title LIKE 'star wars%';)
to use the ID of 58373 (WHERE id='58373';) so that it only changes “Empire”

# sqlite3 com.plexapp.plugins.library.db "SELECT 'UPDATE metadata_items SET added_at=''' || originally_available_at || ''' WHERE id=''' || id || ''';' FROM metadata_items WHERE id='58373';" | sqlite3 com.plexapp.plugins.library.db

For those confused by the SQL command, it is building the UPDATE command inside of a SELECT query, injecting the SELECT return values in the proper locations. The output is then redirected back to sqlite to be executed. If you were to run the command above but without the | sqlite3 com.plexapp.plugins.library.db part, it would simply output the UPDATE command to the console instead. You could use this method to verify the changes before actually doing it.

UPDATE metadata_items SET added_at='1980-06-20 00:00:00' WHERE id='58373';

This kind of SELECT/UPDATE combo works great for multiple entries to dynamically build UPDATE commands. Here is the output of the first command for all of the Star Wars entries.

UPDATE metadata_items SET added_at='1977-05-25 00:00:00' WHERE id='58372';
UPDATE metadata_items SET added_at='1980-06-20 00:00:00' WHERE id='58373';
UPDATE metadata_items SET added_at='1983-05-25 00:00:00' WHERE id='58374';
UPDATE metadata_items SET added_at='2015-12-14 00:00:00' WHERE id='58375';

I am in no way an SQL guru and there is probably a better method to do this but this way has worked well for me. YMMV.

Hope this helps.