Skipping Weekends with Templater Dates?

Things I have tried

Researching documentation and here on the forums… no joy.

The code I’m using, with the Templater plug-in, is

<< [[<% tp.date.now("DDMMMYYYY, dddd", -1) %>]] | <span style="color: green;"><% tp.file.title %></span> | [[<% tp.date.now("DDMMMYYYY, dddd", 1) %>]] >>

Like many, I don’t normally use Obsidian on the weekends, I am, however, a heavy weekday user. That said, is there a way to get this forward/back date template to skip the weekends?

For example, if I click back to yesterday it will create a page for Sunday as I didn’t create one since I didn’t work yesterday.

Thanks.

I’m a complete n00b here, but I have been tinkering with my Daily Notes Templater err… template and hadn’t really thought of this as an issue until you mentioned it… Thanks! :grin:

There may be a much more elegant way to accomplish this, but after a little experimentation, I replaced my “Yesterday / Tomorrow” equivalent to your example with this, culled from the concepts in Bryan Jenks’ Templater Control/Flow published note (Thanks @tallguyjenks!).

<%* if (tp.date.now("ddd", 0, tp.file.title, "YYYY-MM-DD") == "Mon") { %>[Last Friday](<% tp.date.now("YYYY-MM-DD", -3, tp.file.title, "YYYY-MM-DD") %>) <%* } else { %>[Yesterday](<% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %>) <%* } %> / <%* if (tp.date.now("ddd", 0, tp.file.title, "YYYY-MM-DD") == "Fri") { %>[Next Monday](<% tp.date.now("YYYY-MM-DD", 3, tp.file.title, "YYYY-MM-DD") %>) <%* } else { %>[Tomorrow](<% tp.date.now("YYYY-MM-DD", 1, tp.file.title, "YYYY-MM-DD") %>) <%* } %>

I’ve left it as a long single line as I’m not 100% sure if I tried to arrange it into more readable templated Javascript that I’d get all the important syntax in the right places. It’s basically a pair of if/else statements that say if this note is for a Monday, “Yesterday” becomes “Last Friday” and today-3 on the link and, if today is Friday, “Tomorrow” becomes “Next Monday” and today+3 on the link.

When I have more time I might have a think about what to do if I do create a daily note at the weekend, which might be as simple as not inserting those links at all…

PS. can anyone tell me how to insert a code-block into a post? Both pre-formatted and block quote still messed with my layout when I tried to post the multiline code. :pray:

1 Like

Thank you for this. I know very little about JS myself. I’ll give it a try. Again, thank you for taking the time to do this. :call_me_hand:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.