Is there a way to sort a PGN chess game by date and export the sorted games as a new PGN file?
I have not tried this myself, but there is a forum post on chess.com that has instructions on how to do this in SCID (http://www.chess.com/forum/view/help-support/sorting-a-pgn)
- Make an empty scid database
- Import your games
- Do database maintenance - Sort by date
- Export your databse to PGN
I am sure there are many programs that include this functionality. I would be surprised if SCID (http://scid.sourceforge.net/) did not have it. There should be one or more online services that provide this function. In the end of the day, you can write your own script in e.g. Python that does this easily and nicely. The trick is that some games appear as duplicates in less well maintained PGN files. Another trick is that some games are missing certain annotation fields. Some fields could also be filled in with incorrect type of data or simply be empty. So if you go down the road of writing your own scripts, consider writing quality check scripts that make sure the PGN format is followed and that the information is complete.
You can do it with ChessBase: http://chessbase-shop.com/en/products/chessbase12_download
The accepted answer does currently (2021) not work with the latest Scid versions. Bug? But it works with Scid vs PC:
- In Scid vs PC, open the PGN database which you want to sort (File → Open).
- Open the game list, if it is not visible already (Windows → Game List).
- Create an empty Scid database via File → New (make sure it is a
*.si4database, not a
*.pgndatabase). You should now see both database buttons below the game list.
- Select the PGN database by clicking its button.
- Sort the PGN database by your desired criteria. You can do that directly in the game list by clicking on the column headers, or by doing it via Tools → Maintenance → Sort Database (you can reset any sorting by right-clicking a column header in the game list and choosing Reset).
- Drag-drop the button of the sorted PGN database on the button of the empty Scid database. This imports all games, sorted in the same order. Test it by resetting the sorting. The sorting should stay the same as in the sorted PGN database.
- Finally export the Scid database to a new PGN database using Tools → Export All Filter Games → Export Filter to PGN. I recommend to not set the encoding to utf-8, I encountered problems in other databases when I did that.