Thanks moonbase and gilmar!
I had to make some changes to get the code to work with my daily note template that’s based on dannb’s daily note template.
I changed the search to be based on tags, and filtered out the template so there aren’t links to it.
I also changed the code to get dates based on the YAML created tag that I am using.
Finally I made the variable names more descriptive.
/*
previous/next note by date for Daily Notes
Also works for other files having a `date:` YAML entry.
MCH 2021-06-14
https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847/21
*/
var noNotePlaceholder = '(none)';
var notes = dv.pages("#daily").where(note => note.created).map(note => [note.file.name, note.created]).sort(note => note[1]).filter(note => note[1] != "<% tp.file.creation_date() %>");
var currentNoteDate = dv.current().created ? dv.current().created : dv.date("now").toFormat("yyyy-MM-dd");
var dateFormat = 'YYYY-MM-DD';
var formattedCurrentDate = '(' + moment(currentNoteDate).format(dateFormat) + ')';
var navigationLinks = [];
var currentNote = notes.find(notes => notes[1] == currentNoteDate);
var nextNote = notes.find(notes => notes[1] > currentNoteDate);
var previousNote = undefined;
notes.forEach(function (notes) {
if (notes[1] < currentNoteDate) {
previousNote = notes;
}
});
navigationLinks.push(previousNote ? '[[' + previousNote[0] + ']]' : noNotePlaceholder);
navigationLinks.push(currentNote ? currentNote[0] : formattedCurrentDate);
navigationLinks.push(nextNote ? '[[' + nextNote[0] + ']]' : noNotePlaceholder);
dv.paragraph(navigationLinks[0] + ' ← ' + navigationLinks[1] + ' → ' + navigationLinks[2]);