Next week/Previous week

What I’m trying to do

I have been following this guy Habit tracking vault build from SCRATCH explaining how to make a journal with the plugins Periodic Notes, Calendar and Templater. My settings for Periodic notes:

Things I have tried

My daily notes are working fine, but now in my weekly notes I want to make navigations between Next week/Previous week. And I have this code:

[[journal/02_ukentlig/<%moment(tp.file.title, 'YYYY-MM-DD').subtract(1,'weeks').format("gggg-[W]ww")%>|↶Forrige uke]] |[[journal/02_ukentlig/<%moment(tp.file.title, 'YYYY-MM-DD').add(1,'weeks').format("gggg-[W]ww")%>|↷Neste uke]]

This code only gives me a new note called “Invalid Date” when I click the Next or Previous link

I’ve made something similar in my vault.

Here it is for reference:

<< [[Calendar/Periodic Notes/Weekly/<% moment(tp.file.title, "YYYY-[W]WW").add(-1, 'weeks').format("YYYY-[W]WW") %>|Last Week]] | [[Calendar/Periodic Notes/Monthly/<% moment(tp.file.title, "YYYY-[W]WW").format("YYYY-[M]MM")%>|This Month]] | [[Calendar/Periodic Notes/Weekly/<% moment(tp.file.title, "YYYY-[W]WW").add(1, 'weeks').format("YYYY-[W]WW") %>|Next Week]] >>

I’m not sure what exactly isn’t working about your nav button setup, but here are some things I’d try

  • .add(-1, ‘weeks’) instead of .subtract(1,‘weeks’)
  • .format(“YYYY-[W]WW”) instead of .format(“gggg-[W]ww”)

Hope that helps.

1 Like

That really helped! Thanks a lot! :star_struck:

Since you’re using Periodic Notes, another option is to use its date math template tags, which are less verbose than Templater:

←[[{{date-1w:GGGG-[W]WW}}]] | [[{{date:GGGG}}]] | [[{{date+1w:GGGG-[W]WW}}]]→

Which for this week yields:

←[[2023-W37]] | [[2023]] | [[2023-W39]]→

Last I checked the date math documentation had been removed from the README (inadvertently, I think), so you’d have to look at an older version of the file to see it.

1 Like

Thanks! Maybe now I’m starting to understand why my initial setup didn’t work. I was mixing the syntax of periodic notes and templater.

It might be possible to mix them? I think I vaguely recall that Periodic Notes might support some Templater syntax, but maybe I’m misremembering. (I don’t use Templater.)