Skip to content

Instantly share code, notes, and snippets.

@WebInspectInc
Last active February 16, 2023 20:46
Show Gist options
  • Save WebInspectInc/d0fb466cbe87778255b188f3508a52bd to your computer and use it in GitHub Desktop.
Save WebInspectInc/d0fb466cbe87778255b188f3508a52bd to your computer and use it in GitHub Desktop.
A Dataview script for displaying an "On this Day" feature in Obsidian. Read more here: https://obsidian.rocks/supercharge-your-daily-notes-in-obsidian/
```dataviewjs
// update path and minyear if needed
const journalPath = 'Journal/Daily';
const minYear = 2012;
const d = new Date();
const rangeOfYears = (start, end) => Array(end - start + 1) .fill(start).map((year, index) => year + index);
const availableYears = rangeOfYears(minYear, d.getYear() + 1900);
const month = ("0" + (d.getMonth() + 1)).slice(-2);
const day = ("0" + (d.getDate())).slice(-2);
const dateString = month + '-' + day;
availableYears.forEach((y) => {
// you may also have to update this date string, if your files aren't formatted in the default way (YYYY-MM-DD)
var note = dv.page(`${journalPath}/${dateString}-${y}`);
if (note) {
dv.el('span', `[[${note.file.path}|${y}]] `);
}
});
```
@devidw
Copy link

devidw commented Feb 16, 2023

When using in the daily note files directly:

To have this in historic files as well and not bound to the current date, we can use:

dv.current().file.name

This will return the current file name, which we can use to extract month + day to then look up differnt years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment