Use the Templater plugin to create repeating tasks on future (or past) daily notes

I keep track of my admin tasks in my Daily notes. If I have a future task, I will place it in the Task section for that date. The problem: I also have repeating tasks that I want to automatically place in a future daily note, based on the future date of the note.

An example: On May 13th, I might realize that I need to order tickets, but no earlier than the end of the month. If I, on May 13th, place the task on my daily note for May 31st, that note for May 31st, created on May 14th, should have all of the repeating tasks it would normally have had I created the note on May 31.

Enter the template plugin. I use the following code to insert the correct repeating tasks, regardless of when the note is created. I even have some tasks that I want to do on the last Thursday of the month, but only if the month will end on Friday, Saturday, or Sunday. this code handles that as well. Here it is:

<%*
  let dayOfWeek = tp.date.now("d", 0, tp.file.title, "YYYY.MM.DD");

  let dayOfMonth = tp.date.now("D", 0, tp.file.title, "YYYY.MM.DD");
  let year = tp.date.now("YYYY", 0, tp.file.title, "YYYY.MM.DD");
  let month = tp.date.now("M", 0, tp.file.title, "YYYY.MM.DD");
  let lastDayOfMonth;
  if (month == 2) {
    lastDayofMonth = 28;
	if (Math.round((year/4),0) == 0) {
	  if (Math.round((year/100),0) != 0) {
	    lastDayofMonth = 29;
	  }
	}
  } else if (month == 4 || month == 6 || month == 9 || month == 11) {
    lastDayOfMonth = 30;
  } else {
    lastDayOfMonth = 31;
  }

  let doLastDOM = (dayOfMonth == lastDayOfMonth);
  
  if (dayOfWeek == 1) {
    // Monday
	tR += "- [ ] first Monday task" + "\r\n";
	tR += "- [ ] second Monday task" + "\r\n";
  }
  else if (dayOfWeek == 2) {
	// Tuesday
	tR += "- [ ] first Tuesday task" + "\r\n";
	tR += "- [ ] second Tuesday task" + "\r\n";
  }
  else if (dayOfWeek == 3) {
	// Wednesday
	tR += "- [ ] first Wednesday task" + "\r\n";
	tR += "- [ ] second Wednesday task" + "\r\n";
  }
  else if (dayOfWeek == 4) {
	// Thursday
	tR += "- [ ] first Thursday task" + "\r\n";
	tR += "- [ ] secondThursday task" + "\r\n";
	
    /* Last Thursday before month end in weekend */
	doLastDOM = (dayOfMonth >= (lastDayOfMonth - 3));
	tR += "- [ ] Thursday task before EOM occurs on weekend" + "\r\n";

  }
  
  // End of Month Tasks
  if (doLastDOM) {
    tR += "- [ ] first end of Month task" + "\r\n";
    tR += "- [ ] second End of Month task" + "\r\n";
  }
-%>
3 Likes