Moment JS dynamic link to today note, not working

What I’m trying to do

Hi, I’m trying to create dynamic links to today, tomorrow, yesterday, this week, this month, this quarter, and this year, to embed in my periodic notes. I can’t get the link to today’s note to work, all the rest of the links mentioned above work fine.

Things I have tried

First of all, I’m using MomentJS. The inline commands I’ve used are these:

`$= '[['+moment().format("YYYY-MM-DD")+'|Today]]'`
`$= '[['+moment().format("gggg-[W]ww")+'|This Week]]'`
`$= '[['+moment().format("YYYY-MM")+'|This Month]]'`
`$= '[['+moment().format("YYYY-[Q]Q")+'|This Quarter]]'`
`$= '[['+moment().format("YYYY")+'|This Year]]'`

They are adapted for my needs and from this thread:

Also, my folder structure is as follows:


The folder 1-Notes it’s straight in the root folder of the vault, and then inside, I have all the different folders for the daily, weekly and so on.

The link to today’s notes, for some reason, is looking for a daily note in the root folder instead of 1-Notes/1-Daily Notes no matter from which periodic note I’m pressing it. However, the weekly, monthly etc are for some reason looking at their proper path.

I don’t understand why the links to week and month are working fine even though the notes are in a different folder compared to the file with those links, and the commands do not say where to look. However, the link to today’s note is not working, when the actual note is supposed to be linked to, is there in the same folder.

I also tried to use these commands for yesterday and tomorrow, they start from the same base command, and they work fine

`$= '[['+moment().add(-1, 'days').format("YYYY-MM-DD")+'|Yesterday]]'`
`$= '[['+moment().add(+1, 'days').format("YYYY-MM-DD")+'|Tomorrow]]'`

I don't know what to do anymore, any help would be appreciated.

Kind regards.

If it doesn’t need to use moment or js, this works as a DQL inline:

 `="[["+(date(today) - dur("1 day"))+"|yesterday]]"`

I’m sure I solved this in js somewhere though… If the above doesn’t work for you I’ll try to find it.

1 Like

I looked for other threads on this topic but couldn’t find one. I guess I missed it then.

I chose to use JavaScript just because it was the first option I came across, and I am currently studying it. I thought it was a good opportunity to gain some knowledge and experience with it.

Also, I’m not going to lie, I’m very curious as to why the other commands can get the proper path, without even mentioning it, but the one for the daily note does not.

I’m not sure how to format the date for the commands you mentioned, today’s command uses “December 04, 2023” and I need 2023-12-04, also, how to create them for this week, this month, this quarter, and this year.

1 Like

oh I mean I feel like I solved it somewhere in my vault, not the forums! I’ll have a look and get back to you.

1 Like

Hmm, looks like the code you initally pasted works perfectly for me, so I don’t have a way to test the issue for you. Have you configured the day path for your periodic notes plugin? Do you have a clashing daily notes plugin active?

1 Like

It’s all good now, and the funny thing is that I don’t know why it started working again, although I’m happy with it.

I haven’t installed/uninstalled or changed any plugin settings for more than a week now and added these commands just a couple of days ago. The only thing I did was restart my computer, I guess that was it.

Thanks for the help.

1 Like

lol sometimes that’s just how it is. good luck with the js learning!

1 Like

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