Fix Last Modified Dates on Notes when Migrating to Obsidian
In this quick blog post, we’ll take a look at a problem that frequently plagues people who are migrating to Obsidian from another notetaking platform.
Warning: Remember that you should always fully understand what a command or script does before running it on any computer. This fix is not associated with Obsidian and its developers, nor is it guaranteed or warrantied in any way. Use at your own risk, and always have a backup!
When you export all of your notes from the platform you’re leaving, the Last Modified datetime for all of the notes will appear as the date you exported them from the other notes platform. While that’s technically true, we’ll want to make sure that this gets fixed to reflect the actual datetime that the note(s) were last modified.
This fix will require that all of your notes contain Properties in their YAML frontmatter. The main property that we are concerned with is the
Last Update property.
With a little bit of help from PowerShell, we can easily resolve this issue using a script that I threw together after a conversation with some other Obsidian users in the Obsidian Members Group Discord Server.
The first thing we need to do is enumerate all of the notes in your Obsidian Vault:
Next, we need to loop/iterate through all of those notes, read the content of the note to get the
Last Update property from the YAML frontmatter of the note, and then set the
LastWriteTime property of the note file to that value:
Get the Script
You can download the script for your own free use by:
- Right-click your Start Menu
- Select Windows PowerShell
- Copy/Paste this command into PowerShell and press ENTER:
Once you’ve downloaded the script, open it in Notepad:
$vault value to reflect the file path to the root folder of the Obsidian Vault, then save and close it.
Go back to PowerShell, and do
.\fix_last_modified_dates.ps1 and press ENTER.
This script should be able to assist you with fixing the Last Modified date that shows up in File Explorer for all your notes in your Obsidian Vault that were previously exported, which resulted in all their dates being the same. I hope that this was helpful to you!