A Templater command to return the month of a certain day?

Hi all,

I’m looking for some community inspiration :grin:

I have a weekly template, whose title is in the format “GGGG-[W]WW”. In my weekly note for this week, for example, this renders to “2022-W39”. What I want to do is link this weekly note to its associated monthly note. The thing is, the ISO standard does not assign weeks to months, only weeks to years. So my idea is to assign a month myself, based on which month the Thursday of the week falls in (in this case, the Thursday of Week 39 is on September 29, so Week 39 would be assigned to September).

To do this, I’m trying to create a Templater command to return the month in which the Thursday of the week falls. Essentially, what I want to tell Templater to do is:

Return “YYYY-MM” containing tp.date.weekday(“YYYY-MM-DD”, 3, tp.file.title, “GGGG-[W]WW”)

Does anyone have any ideas? Thanks in advance!

Super easy, put this in your template:

moment(tp.file.title, 'GGGG-[W]WW').add(3, 'days').format('MMMM')

Descriptively, that’s:

  1. Create a date from the title of the note, using the format GGGG-[W]WW
  2. That’s an ISO week date (WW), so add 3 days to get to Thursday
  3. Output in the format of just the month

Thanks very much for your reply, @AlanG. I’m guessing I need to wrap this inside the <%* and %> tags, as this is referencing the moment.js object, is that correct?

I found that this works using just the regular Templater <% %> tags.

This command works perfectly; thanks!

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