Beginner question - how to create a linked Monthly Log with connections to each daily log?

What I’m trying to do

Please let me preface this by admitting I know this has likely been asked a thousand times, but for some bizarre reason I just can’t seem to find a solution, so I am now resigned to ridicule. FOR SCIENCE!

It’s all for science.

Anyway, here’s my problem - I have a set of daily notes in the form of ‘2024-12-20 Friday’, all constructed from a somewhat wacky template using templater. I have a set of monthly logs that contain a table, each row representing a day, for me to write a short series of remarkable events, like

3 - Finally met the Empire of Antares.
4. - Starbases at the rim destroyed. God help us all.

I’d like that the number of the day to be a link to the corresponding day. I know it’s possible and likely involves templater, but I just can’t seem to figure it out.

Things I have tried

Did multiple web searches. Banged my head against the wall. Drank to the gods of irony. Now considering more extreme measures. Please send help.

The Antarens are coming.

Hi @Gilgeam,

first of all, I love your humor :smiley: .

To clarify your requirements a bit.
You have a monthly note in which you want links to the daily notes of that months with additional lines to put another short sentence?

Or do you just need a list of all daily notes of that month (via dataview query for example)?

1 Like

One way could be to get Templater to run a loop, and insert lines of the form:

| [[2024-12-20 Friday \| 03 ]] |   |

But what is your question? Is it how to write that loop, or how to add an alias into the table (like shown in the example above)? Or something entirely different? Like how to list existing daily notes already present?

1 Like

Thank you! If the Antarens keep crawling towards us, pretty soon humor will be all I have left. But! Don’t panic! I have plans for a superweapon that involve a bubblegum, a catapult, a very, very large piece of cheese, and a pair of sunglasses. It’s not a very good plan, but it has the distinct advantages of being both novel and stupid, unlike my usual plans, which are usually only stupid!

So - progress! FOR SCIENCE!

As to what I’m hoping to get, here’s the gist:

I have a table inside my template somewhat formed like

1 |
2 |
3 |

31 |

And I’d like the numbers to automatically be linked to the relevant daily notes, so it becomes

[[2025-01-01 Wednesday|1]] |
[[2025-01-02 Thursday|2]] |

My problem is that not only am I only vaguely capable of coding that in the first place, I don’t quite know how to get templater to 1) start this list on the very first and not relative to whatever day it is, which most examples seem to be focused on, and 2) get it to actually conform to the somewhat weird naming convention.

So ideally I’d love to find something like

[[TemplaterGoesYay]] |
[[TemplaterGoesYay]] |

code that I can add to my template and would translate to above dates, so I just have to fill in the notes and end up with something like

4 | The plan has failed! Who knew cheese would be so aeronautically challenged?!
5 | I have only one word for you: hummus.

I just don’t know if that’s reasonable to hope for or if Dataview isn’t an easier fix. Currently, every month, I use my current monthly log template and then manually type in above links for every day, but automating that would be sweet.

I… hope this clears it up? Again, my sincere apologies for this mind-blowingly stupid question. If I wasn’t busy preparing my hummus defence against certain doom, I might have already perished from pure shame.

This Templater template assumes you want to create the table based on the current month.

<%*
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

const year = tp.date.now("YYYY");
const month = tp.date.now("MM");
// Creating a date object for the first day of the next month
const nextMonth = new Date(year, month, 1);
// Subtracting one day to get the last day of the current month
const lastDayOfMonth = new Date(nextMonth - 1);
// Extracting the day (which gives the number of days in the current month)
const daysInMonth = lastDayOfMonth.getDate();

const datePrefix = tp.date.now("YYYY-MM");
let table = [];
table.push("| Day | Comment |");
table.push("|-----|:----------|");

for (let day = 1; day <= daysInMonth; day++) {
	const dayString = day.toString().padStart(2, "0");
	const date =`${datePrefix}-${dayString}`;
	const d = new Date(date+"T12:00:00Z");
	// Get the Day of the Week
	const dow = days[d.getDay()];
	// Create a new link row
	table.push(`| [[${date} ${dow}\\|${dayString}]] |  |`);
}

tR += table.join("\n");
%>
1 Like

After reading your comments closer, I noticed you don’t use leading and trailing | in your tables. This template follows that table format preference…

<%*
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

const year = tp.date.now("YYYY");
const month = tp.date.now("MM");
// Create a new date for last day in month and get that day number.
const daysInMonth = new Date(year,month,0,0,0,0,0).getDate();

const datePrefix = tp.date.now("YYYY-MM");
let table = [];
table.push("Day | Comment");
table.push(":--:|:-------");

for (let day = 1; day <= daysInMonth; day++) {
	const dayString = day.toString().padStart(2, "0");
	const date =`${datePrefix}-${dayString}`;
	const d = new Date(date+"T12:00:00Z");
	// Get the Day of the Week
	const dow = days[d.getDay()];
	// Create a new link row
	table.push(`[[${date} ${dow}\\|${dayString}]] | `);
}

tR += table.join("\n");
%>

[Edit: more compact way of calculating daysInMonth]

1 Like

This is incredible work and I’m beyond impressed. Incidentally and likely unrelated, I’m also a dummy. I simplified the layout of the table a little to make it easier to write on my mobile phone, which unfortunately makes a small difference for the solution.

Day Notes
1 [[2024-12-01 Sunday| 日]] Note Day 1

So I went with your first layout and that just turns out beautifully. I wonder though if it’s possible to modify your brilliance to this. The odd symbols used to the titles of the links are called Kanji and represent the day of the week in the Japanese locale. I can rewrite your template to conform to most of it, but I’m not sure if it’s possible to have templater check for the current weekday and insert the dddd call in Japanese. I know it’s possible to define something like

<%* moment.locale(“jp”) -%>

for the file, but I think that would leave me unable to get the ‘Monday’, ‘Tuesday’ and so on, so the locale would need to be changed for a single call. Not sure if that’s even possible?

I tried to get the table to format correctly but it somehow turned out worse and can no longer be edited. This is what I was going for:

Day Notes
1 [[2024-12-01 Sunday| 日]] Note Day 1
2 [[2024-12-02 Monday|月]] Note Day 2
3 [[2024-12-03 Tuesday|火]] Note Day 3

I gave this some further thought and realized I was overcomplicating things.

I was thinking that in the loop, I only need to check the dow string and format the string to be inserted, so something like

if (${dow}== “Saturday”) {const kanji="土“};
else if (${dow}== “Sunday”) {const kanji="日“};
else if (${dow}== “Monday”) {const kanji="月“};
else if (${dow}== “Tuesday”) {const kanji="火“};
else if (${dow}== “Wednesday”) {const kanji="水“};
else if ${dow}== “Thursday”) {const kanji="木“};
else {const kanji="金“};

And then inserting that kanji string in the table push seemed smart, but I probably stumbled along the way because this throws an error.

How about this?

<%*
const dnames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const jnames = ["日","月","火","水","木","金","土"];

const year = tp.date.now("YYYY");
const month = tp.date.now("MM");
// Create a new date for last day in month and get that day number.
const daysInMonth = new Date(year,month,0,0,0,0,0).getUTCDate();

const datePrefix = tp.date.now("YYYY-MM");
let table = [];
table.push("Day | Notes");
table.push(":--:|:-------");

for (let day = 1; day <= daysInMonth; day++) {
	const dayString = day.toString().padStart(2, "0");
	const date =`${datePrefix}-${dayString}`;
	const d = new Date(date+"T12:00:00Z");
	// Get the Day of the Week (0-6)
	const dow = d.getUTCDay();
	// Create a new link row
	table.push(`${day} [[${date} ${dnames[dow]}\\|${jnames[dow]}]] | Note Day ${day}`);
}

tR += table.join("\n");
%>

[Edit: cleaned up code a little]

1 Like

This version is formatted with fully enclosed table markdown, since you mentioned that the original format worked better for you.

<%*
const dnames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const jnames = ["日","月","火","水","木","金","土"];

const year = tp.date.now("YYYY");
const month = tp.date.now("MM");
// Create a new date for last day in month and get that day number.
const daysInMonth = new Date(year,month,0,0,0,0,0).getUTCDate();

const datePrefix = tp.date.now("YYYY-MM");
let table = [];
table.push("| Day | Notes |");
table.push("|:---:|:------|");

for (let day = 1; day <= daysInMonth; day++) {
	const dayString = day.toString().padStart(2, "0");
	const date =`${datePrefix}-${dayString}`;
	const d = new Date(date+"T12:00:00Z");
	// Get the Day of the Week (0-6)
	const dow = d.getUTCDay();
	// Create a new link row
	table.push(`| ${day} [[${date} ${dnames[dow]}\\|${jnames[dow]}]] | Note Day ${day} |`);
}

tR += table.join("\n");
%>
1 Like

This… is perfect. Simply perfect. It’s beautiful, it’s concise, and it’s also so ludicrously efficient that I’m baffled the amount of work I spent manually doing this can consistently be outshone by this.

Really… In the right hands, coding is a form of magic. You just gotta love it!

THANK YOU SO MUCH! This is amazing, and you are a true magician!

1 Like

Since youce been so incredibility kind, I just wanted to ask - I’ve been toying with the idea of adding a prefix or suffix to the day link on certain days, like

Middle of the week [[…]] or
[[…]] Holiday

Specifically, I was considering marking the weekend days and Wednesdays with a pre- or suffix to make the last more readable. I haven’t really narrowed it down yet which makes more sense, but I just got curious - can the script be modified for something like this? How would you go about this?

If the prefix/suffix you want happens on the same day each week, you can make another array similar to…

const dnames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const jnames = ["日","月","火","水","木","金","土"];
const prefixes = ["Weekend ", "", "", "Middle 🐪 ", "", "", "Weekend "];

then you will modify the following line by inserting ${prefixes[dow]} in your preferred location, maybe like…

table.push(`| ${day} ${prefixes[dow]}[[${date} ${dnames[dow]}\\|${jnames[dow]}]] | Note Day ${day} |`);

Something fancier would require knowing your exact needs, and I’ll leave as an exercise for the interested reader :grin:

1 Like

Again, thank you so much! This is perfect! I played around with it and with the way the array is set up, I can easily add all sorts of text tweaks to everything now that I understand the general principle. It gives me a huge amount of freedom over everything!

Thank you SO MUCH!

1 Like