Embed a link to today’s note

Published with Share Note 🔸 Part of Obsidian guides

If you put this code into a note (including the first line), every time every time that note is visible on your screen the Dataview code will execute and update the embed link to be the current date.

This also works fine from a canvas or from pinning a note in the sidebar, and automatically updates the embedded note to today.

Note: You will need to update my date format YYYY-MM-DD dddd to match the one you’re using.

![[2023-09-27 Wednesday]]
 
```dataviewjs
// The date format for your periodic/daily notes
const dateFormat = 'YYYY-MM-DD dddd'
// Get the current file
const file = app.vault.getAbstractFileByPath(dv.current().file.path)
// Get the text contents of the current file
let contents = await app.vault.read(file)
// Update any text on the line before  to be an embedded link to today's note
contents = contents.replace(/^.*?$/m, '![[' + moment().format(dateFormat) + ']]')
// Save the new contents back to the current file
await app.vault.modify(file, contents)
```

Asked in these threads: