Can I schedule daily activities based on the day of the week in my notes?

Things I have tried

I believe templater can be handy, but I’ve never used it and ideally would like to find a solution that doesn’t involve coplexify my vault further.


I’m trying to schedule different tasks based on the day of the week.
For example, I want some tasks to show-up Mon. and Fri., others all weekdays and some on Sat. only, is this possible at all?

If yes, do you have any suggestion on how to achieve it?

Thank you

What I’m trying to do

This could probably be cleaned up, but can hopefully get you started. It uses execution commands in Templater, generally following this example:

<%* if (Number.parseInt(moment(tp.date.now("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD")).format("e")) === 6) { %>
- [ ] Sunday tasks
<%* } else { %>
- [ ] Tasks for other days
<%* } %>

It assumes you’re using daily notes that have their file names in the YYYY-MM-DD format. This could be simplified to moment() (excluding all the tp.date.now() stuff), but by including that it should properly handle notes that are created on a different day (e.g., the night before).

Adjust === 6 based on your locale setting (if your week starts on Sunday, you’d want to change 6 to 0).

1 Like

thanks you @geoffb, I do have the daily notes set in the mentioned format.

As a total Templater noob, where do I copy the snippet?

I would paste that snippet into my Daily template in the location where I want my tasks (e.g., the output) to appear.

Note: I would change the Templater closing tags from %> to -%>, to better deal with white space. There are three instances of them.

1 Like

I must be missing something.

have copied the snippet in the daily note template, but this is the result I get when creating a new note:
image

In other words, I get back the exact same snippet I’ve copied

To be sure, you’re using the daily note template (where the snippet was added) and after creating a new daily note, the templater code remains? Are there any errors on the page? Does your daily notes template produce a file named in the format YYYY-MM-DD?

Is this helpful from @ScottKillen Use the Templater plugin to create repeating tasks on future (or past) daily notes

I’d approach the template in the following manner:

<%*
const sun = tp.date.now('ddd',0,'2023-02-05','YYYY-MM-DD');
const mon = tp.date.now('ddd',0,'2023-02-06','YYYY-MM-DD');
const tue = tp.date.now('ddd',0,'2023-02-07','YYYY-MM-DD');
const wed = tp.date.now('ddd',0,'2023-02-08','YYYY-MM-DD');
const thu = tp.date.now('ddd',0,'2023-02-09','YYYY-MM-DD');
const fri = tp.date.now('ddd',0,'2023-02-10','YYYY-MM-DD');
const sat = tp.date.now('ddd',0,'2023-02-11','YYYY-MM-DD');
const day = tp.date.now('ddd',0,tp.file.title,'YYYY-MM-DD');

//Example: Every Tuesday
if (day === tue)
{
   tR += '- [ ] a\n';
}

//Example: Every weekday
if (day === mon || day === tue || day === wed || day === thu || day === fri)
{
   tR += '- [ ] b\n';
   tR += '- [ ] c\n';
}

//Example: Every Tuesday and Thursday
if (day === tue || day === thu)
{
   tR += '- [ ] d\n';
}
-%>
- [ ] e (happens every day)

Basically, this template computes the local abbreviation for each day of the week so I don’t have to worry whether the week starts on Sunday or Monday. You can then use these constants to compare against the day-of-the-week of the note’s filename. I append to the Templater global variable tR the tasks that should be output for a given day. Be sure that each one ends with \n to return to the next line. Any tasks that occur everyday are listed outside the Templater script.

I find this style a lot more readable and flexible than trying to intersperse content and code.

Running this template on a note with today’s date (2023-02-07 which is a Tuesday) results in the following output:

- [ ] a
- [ ] b
- [ ] c
- [ ] d
- [ ] e (happens every day)

For one with tomorrow’s date (2023-02-08 which is a Wednesday), I get:

- [ ] b
- [ ] c
- [ ] e (happens every day)

1 Like

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