Templater plugin is creating wrong week (only in weekly note, not in daily note))

Hi guys!

Sorry to ask this question but I getting crazy here…
I am working on my daily, weekly, monthly notes and I have a strange issue with the templater plugin:

We are in calender week 3 now and this line in the frontmatter…

week: <% tp.date.now(“YYYY-[W]ww”, 0, tp.file.title, “YYYY-MM-DD”) %>

… is generating in the daily note the correct week:

Daily Template


tags: daily-note
week: <% tp.date.now(“YYYY-[W]ww”, 0, tp.file.title, “YYYY-MM-DD”) %>


week: 2023-W03

… but the same line of code in the weekly note is creating the wrong week:


tags: weekly-note
week: <% tp.date.now(“YYYY-[W]ww”, 0, tp.file.title, “YYYY-MM-DD”) %>


week: 2023-W09

Heres the directly comparison:

Do you have some hints for me? I really tried everything?
Thanks a lot!

Regards, Steffen

Do you have the file names of those examples? If you look at tp.date - Templater, you’ll see that you’re trying to lock the date for that format string from the file name.

Weekly Template Steffen.md (2.3 KB)
Daily Template Steffen.md (4.1 KB)

image

image

OK, so I’ve condensed your issue down into this template:

## Original
<% tp.date.now("YYYY-[W]ww", 0, "2023-W03", "YYYY-MM-DD") %>

## Modified reference format
<% tp.date.now("YYYY-MM-DD", 0, "2023-W03", "YYYY-[W]ww") %>

Which produces this output:
image

The point is that in the first line it’s to be understood as:

  • Function call of tp.date.now(): Until further notice lets work with todays date
  • First parameter: Display whatever date we’re using according to this format: “YYYY-[W]ww”
  • Second parameter: Offset the date we’re working with by this much, 0 meaning no offset
  • Third parameter: By the way, we don’t want to use today, but we want to use the date referenced here. (In my text example, the fixed value of “2023-W03” (and in your case the file name)
  • Fourth parameter: AND the date in the third parameter, follows this date format

In other words, you’re asking Templater to understand “2023-W03” as if it was written as “YYYY-MM-DD” whilst it clearly is not in that format. This confuses Templater so much, and in an effort to give you some result it interprets this as the date “2023-03-01”, which in fact is in “W09”.

In the second line, I tell Templater to interpret it as the format it is in, and it reports back the date of that week, which is the first day of that week.

If you specify an alternative date, like with tp.file.title, you need to specify which date format that file title has in the fourth parameter.

A question for you though, if the file title already is in the format YYYY-[W]ww, then why do you convert into a date to report it back in the same format as it was? Wouldn’t it be easier just to do:

week: <% tp.file.title %>
2 Likes

Thanks @holroy! Very nice explained and everything undertood. You are my hero! :grinning:

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