Preserve Creation Dates when Using Obsidian Sync

I can confirm that this indeed is the case. My experience is that Obsidian is applying some internal process that is changing the file’s creation date under-the-hood whenever I modify a note. As others note, it renders Dataview queries that rely on the creation date useless. Our choices are really only to maintain a cdate field in the frontmatter or encode a timestamp in the note name (in the manner of a ZK note, for example.) The latter is what I do, e.g. 20230529062543 Foo bar note.

I then run a user agent that finds files in the Obsidian vault directory that were “created” in the last n minutes, then parse the timestamp out of the note name and use that to reset the creation date.

#!/bin/bash

OBSDIR="/path/to/my/obsidian/vault"
FILES=$(find "$OBSDIR" -type f -newerBt "$(date -v-15M)" | grep -E '[0-9]{14}')

if [ "${#FILES[@]}" -gt 1 ]; then
	echo "Obsidian has ${#FILES[@]} ZK files with new creation dates."
fi

IFS=$'\n'
for FPATH in $FILES; do
	FN=$(basename -- "$FPATH")
	ACTUAL=$(echo "$FN" | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2}).*/\2\/\3\/\1 \4:\5/g')
	setfile -d "$ACTUAL" "$FPATH"
done

Note: macOS only as setfile is included in the macOS command line developer tools.

I really hate that this is necessary, but the file creation date should not be subject to change inside Obsidian.

1 Like