Auto Assign Week Number to Daily Notes

What I’m trying to do

I’m trying to assign the week number to daily journal notes and it’s working except Mondays are assigned to the prior week. For example, Monday 9/23/2024 gets assigned Week 38 instead of 39. Monday 9/30/2024 gets week 39 instead of 40. Tuesday and the other days work fine.

I’m using Templater, Periodic Notes and Calendar.

My goal is to surface a list of the daily notes from the week in the weekly journal entry with a few key properties to help me reflect on the week. I’m very close and feel this will be a really helpful step to my journal process and reflection. Any help greatly appreciated.

This is the code I’m using.

<%*   
const thisDay = window.moment(new Date(tp.file.title));
const thisWeek = thisDay.format("YYYY-[W]ww")
-%>
---
week: <% thisWeek %>
---

Things I have tried

In calendar I’ve set the week to start on Monday. The Locale is set to En/US. I’ve tried searching the forums and googling. I checked Templater and Moment docs but can’t find anything.

Here is a screenshot of the result when I click Monday 9/30/2024 from calendar and create a new daily note. You can see the wrong week in the properties.

I’m not sure what your issue is, but I reckon you could possibly check if its Monday and correct the week number, or add an offset to your current date to make it correct.

You might also look into whether your date format sybtax is using the ISO week or not, and whether the alternate works better for you.

Thanks. I tried ISO date and that didn’t change anything. I can look into adding an adjustment for Mondays. That is obviously a bit of a kludge and implies there is a bug in the week assignment of Moment or Templater. Lots of people use this I think so I’m still hoping there is something obvious I’m doing wrong that can be fixed rather than having to add a +1 every time it’s Monday.

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