I want to be able to create a dynamic link to yesterdays daily note.
Precondition
The format for my daily notes in its plugin settings is YYYY-MM-DD-ddd, translating to a filename of e.g. “2024-10-17-Thu”.
What I tried
Inspired by this topic here I created a dynamic link with an inline dataview script like this: ="[[" + dateformat(date(today) - dur(1day), "yyyy-MM-dd") + "|Yesterday]]"
Which is working, but won’t link as the name of my daily notes are different.
Changing above inline script to ``=“[[” + dateformat(date(today) - dur(1day), “YYYY-MM-DD-ddd”) + “|Yesterday]]”` results in this message though:
““YYYY-10-16 Oct 2024-ddd” is not created yet. Click to create.”
So basically what I need to know is: how do I specify the format I am using in the daily plugin with an internal dataview?
Your suggestion will keep changing to always link to yesterday, and not take into consideration what the actual date of today is…
A better solution would be to use something like: `= link(dateformat(this.file.day - dur(1day), “yyyy-MM-dd-ccc”), “Yesterday”) ` where we create the link based upon the date used in the file name.
Some key points why this works:
this.file.day – Will pull the date either from the file name, or a property called date. Since your file name includes the proper YYYY-MM-DD somewhere in the file name, it’ll use this
Build the entire link – It’s safer to build the entire link within the query, instead of partically patching together the [[ and so on. Doing the entire link gives a proper rendering in more cases, whilst patching it together requires some rendering magic to happen later on (which often is the case, but not always)
Luxon vs moment date formatting tokens – Many plugins (and Obisdian core) mainly uses moment date formatting tokens, where YYYY-MM-DD-ddd would denote your date string. But Dataview, and some other plugins, uses Luxon date formatting token, so the equivalent would therefore be: yyyy-MM-dd-ccc. See dateformat(), and here is an online tool converting from momemt to Luxon: https://moment-to-luxon.vercel.app