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

A bit late to the party, but I was wondering whether this could be adjusted to not only work with the current day (tp.now(format)) but also with any other daily note (with formated title) using tp.date.now(format, source, inputformat) .

I gave it a try. I renamed today, yesterday and tomorrow to thisday, daybefore, dayafter (bc. it will be relative to the notes title date).

Also like OP mentioned, by locale makes the week start with monday on 0, so if you’re looking for those changes you can find them here.
My files names are also just the date - no - daily in there.

The result should be a 6th level Navigation Heading with linking to the (work)day before, that day’s weekly and monthly note, and the following (work)day. It should be easy to remove the weekly and monthly note for you.

Monday KW 15 - Navigate

[[2025-04-04| << Previous Day]] | [[ 2025W15|This Week]] | [[004-April-2025|This Month]] | [[2025-04-08|Next Day >>]]

And here the code:

###### <% tp.date.now("dddd", 0, tp.file.title, "YYYY-MM-DD") %>  KW <% tp.date.now("WW", 0, tp.file.title, "YYYY-MM-DD") %> - Navigate
[[ <%*
const thisday = tp.date.now("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD");
const thisMonday = tp.date.weekday("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD");
const lastFriday = tp.date.weekday("YYYY-MM-DD", -3, tp.file.title, "YYYY-MM-DD");


let daybefore;
if (thisday === thisMonday) {
    daybefore = lastFriday;
} else {
    daybefore = tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD");
}

tR += `[[${daybefore}| << Previous Day]]`;
%> | [[ <% tp.date.now("YYYY",0, tp.file.title, "YYYY-MM-DD")%>W<% tp.date.now("WW",0,tp.file.title,"YYYY-MM-DD")%>|This Week]] | [[<% tp.date.now("00M-" + "MMMM-YYYY") %>|This Month]] | <%*
const thisFriday = tp.date.weekday("YYYY-MM-DD", 4, tp.file.title, "YYYY-MM-DD");
const nextMonday = tp.date.weekday("YYYY-MM-DD", 7, tp.file.title, "YYYY-MM-DD");

let dayafter;
if (thisday === thisFriday) {
    dayafter = nextMonday;
} else {
    dayafter = tp.date.now("YYYY-MM-DD", 1, tp.file.title, "YYYY-MM-DD");
}

tR += `[[${dayafter}|Next Day >>]] `;
%>


1 Like

Tiny edit (and I only noticed after the post couldn’t be edited anymore:
In the second line, remove the 2 leading [[ in front of the first multi line templater code (<%*)