Skipping Weekends in Templater Daily Note Links

I currently use Daily Notes in a work vault and am using Templater to insert links to yesterday & tomorrow’s daily notes at the top of every daily note to ease navigation. However, since I don’t work on the weekend (Sat/Sun) I was looking for a solution that could skip weekends. I found this forum post but thought I’d also share my solution as it’s a touch easier to read!

Note that this is set for a US locale where Sunday = 0 in tp.date.weekday – if you’re in a locale where Monday = 0, you’d need to adjust the tp.date.weekday numbers to match.

This is my template code for the yesterday link:

<%*
const today = tp.date.now("YYYY-MM-DD");
const thisMonday = tp.date.weekday("YYYY-MM-DD", 1);
const lastFriday = tp.date.weekday("YYYY-MM-DD", -2);

let yesterday;
if (today === thisMonday) {
    yesterday = lastFriday;
} else {
    yesterday = tp.date.now("YYYY-MM-DD", -1);
}

tR += `[[${yesterday} – daily]]`;
%>

And this is my code for the tomorrow link; since I’m already using the code segment above in my template, I don’t re-declare the today variable here. If you’re using the below stand-alone, you’d want to grab that from above.

<%*
const thisFriday = tp.date.weekday("YYYY-MM-DD", 5);
const nextMonday = tp.date.weekday("YYYY-MM-DD", 8);

let tomorrow;
if (today === thisFriday) {
    tomorrow = nextMonday;
} else {
    tomorrow = tp.date.now("YYYY-MM-DD", 1);
}

tR += `[[${tomorrow} – daily]]`;
%>
1 Like