Daily Note: code for going back a day doen't work

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

I often need to go back to the previous day and review or update a previous Daily Note. I found a function in a “how to” video, but it doesn’t work. Below is the code. Can anyone tell me what is broken?

Things I have tried

%<fileDate = moment(tp.file.title, ‘YYYY-MM-DD’)subtract(1,d).format(‘YYYY-MM-DD’) %>Yesterday

This could work (using the community plugin Templater)… and applied to a note where the title follows the format YYYY-MM-DD:

[[<% moment(tp.file.title, "YYYY-MM-DD").subtract(1, 'd').format("YYYY-MM-DD") %>|Yesterday]]

Or this:

[[<% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %>|Yesterday]]

See here for more info about tp.date.now()

First of all you got a syntax error in your code.

Instead of %< the opening tag for Templater script is <%.

Anyway, better solution maybe the following using dataview plugin, for it also covers the possibility of missing days in your logs, just in case.

<< `$= dv.pages('"<your daily log folder>"')
.where(p => p.file.day && p.file.day < dv.current().file.day)
.sort(p => p.file.day, "desc").file.link.limit(1)` | `$= dv.pages('"<your daily log folder"')
.where(p => p.file.day && p.file.day > dv.current().file.day)
.sort(p => p.file.day, "asc").file.link.limit(1)` >>

Resulting in something like << 2024-10-01 | 2024-10-05 >>.

Thank you. I have templater, although I haven’t gotten productive with it yet. The code is in a template that I created. The first line, which is simply the date and time works fine. The next line of code is what I have shared. I will give your suggestion to try the .now function. I will update post later today.

THANK YOU

1 Like

Hi, I like the idea of using Dataview, especially the idea/function of scrolling dates back and forth. I have been struggling with Dataview, but this may be a good catalyst in helping learn it more effectively. Thank you.

I will update post shortly.

Note that any code executed by Templater will produce the correct previous/next link at the time of inserting the template. So unless you want it to always refer to yesterday and tomorrow for any given date, a dynamic solution like the one using Dataview would be a better option.

Templater is never “re-executed” at a later time, so if you originally had the previous note to be a month earlier, and later on added a note in between those two notes it wouldn’t be linked by the previous link.

Great heads on the Templater notation executable (no pun intended).

Dataview is another plugin that I have and do not have a full appreciation for yet, but need to develop.

I tried the code but it didn’t work. All of the examples that I have seen for Dataview code begin and end with \. The example that you provided begin and end with << >>.

What am I not understanding?

Thank you in advance.

You can leave the << >>. In my example it was just to have some visual indicator that you are going forward or backward, but it’s not part of the coding.

EDIT: The code snippet I provided will work in any case, as long as you

  • have installed and activated Dataview plugin
  • your daily notes have a date in their title
  • you copy and paste the snippet as it is directly in your template (or any other note with a date in its title)
  • you replace the string <your daily log folder> with the path to the folder you store your daily notes in, so it will look something like this dv.pages('"CALENDAR/DAILY"')
  • you even can leave it blank (regardless of using a folder for your daily notes or storing them under root), when it will look like dv.pages()

If you run Dataview, would this work for you? Can be customized, of course.

`="[[" + dateformat(date(yesterday), "yyyy-MM-dd") + "|◀️🅨]]"` | `="[[" + dateformat(date(today), "yyyy-MM-dd") + "|🅣▶️]]"`

Ahh, thanks for explaining the << >>. I read it that way when I first saw your post, but my brain checked out and I got lost in my own entanglement. I’ll experiment and post a reply over the weekend.

Thank you…

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