Transclude variable today date note

Things I have tried

![[<%+“YYYY-MM-DD”)%>]] ← that thinks you want to transclude the note named literally “<%+“YYYY-MM-DD”)%>” even though without the ![[ ]] the correct date displays

I also tried using inline dataviewjs like this:
$= dv.current().file.mtime

but I can’t even figure out how to change the date format - it just shows the date like “11:08 pm - October 05, 2022”

What I’m trying to do

I want to set up a workspace where I include a fixed pane that displays the note for todays date

e.g. ![[2022-10-05]]

(which is obviously different every day). So I thought it should be possible to just transclude based on the variable “Date” somehow. I just cant figure out how to get that to work.

About dataview side (I’m not versed in Templater), you can try something like this:

const pages = dv.pages().where(p =>"yyyy-MM-dd") =="today").toFormat("yyyy-MM-dd")).file.path

dv.span(dv.fileLink(pages[0], true))

But I have the idea that embeds in dataview aren’t yet a very stable / reable things (sometimes works, others not; need to jump to another note and return…). But try. :slight_smile:

If I do this from what you provided

const pages = dv.pages().where(p =>"yyyy-MM-dd") =="today").toFormat("yyyy-MM-dd")).file.path dv.span(dv.fileLink(pages[0], true))

I get this error

Dataview (for inline JS query ‘moment(t.text, ‘YYYY-MM-DD’)’): TypeError: Cannot read properties of undefined (reading ‘text’)
Evaluation Error: SyntaxError: Unexpected identifier ‘dv’
at DataviewInlineApi.eval (plugin:dataview:19597:21)
at evalInContext (plugin:dataview:19598:7)
at asyncEvalInContext (plugin:dataview:19608:32)
at DataviewJSRenderer.render (plugin:dataview:19629:19)
at DataviewJSRenderer.onload (plugin:dataview:19213:14)
at e.load (http://localhost/app.js:1:730611)
at e.addChild (http://localhost/app.js:1:731035)
at Object.addChild (http://localhost/app.js:1:1616920)
at DataviewApi.executeJs (plugin:dataview:20138:19)
at DataviewPlugin.dataviewjs (plugin:dataview:20386:18)

Any suggestions?

To start, what I write isn’t an inline query (it’s a dataviewjs block query).
In js case you can use it as an inline query, but you need to separate things (if no break line you need to use “;”). So

`$= const pages = dv.pages().where(p =>"yyyy-MM-dd") =="today").toFormat("yyyy-MM-dd")).file.path; dv.span(dv.fileLink(pages[0], true))`

Second point:

this part doesn’t seem to be related with start query! Where’s text?

ok, We’re half way there, the thing you posted there does generate the correct “today date” in view mode, but when I surround it by [[ ]] brackets, the brackets treat what’s inside them as the text of the code rather than today’s date :frowning:

any ideas?

why you want to add brackets?
sorry but I don’t understand what you’re trying to do.
the code search for pages with the date in title (in format “YYYY-MM-DD”) and select only the pages (I hope only one) with “today” date. in the code"today") is in fact the today date… don’t need to change anything!

I want to have a single generic note that I can pin somewhere that transcludes the note of the current date.

E.g. for today this would work:

, but tomorrow that would not work because it’ll be the wrong day.

So I was thinking I should be able to programmatically have a note something like this:

![[(magic formula to generate todays date)]]

in order to achieve the same result but for every current day instead of just today the one time.

First point: the proposed query do all that, don’t need to add the code between brackets (and inline code between brackets doesn’t work).

Second point:

As I said, sometimes it works and others not (in this case it renders only the file name and you think that is a today date, but is the file name). Try the query in a new note, without other content (just to reduce the render efforts) and if it renders only the name, change to other note and return… sometimes works. (I don’t know the technical apparatus involved, but seems a very unstable thing)

for the time-being I’m achieving the goal by adding a line to a bash script I run at 3am to update the file to reflect the new date:

 echo "![[${today}]]" > "${Filepath}/"

But having said that, I’m still curious if what I describe can be acheived as it would probably be useful for other things :slight_smile:

So if anyone else figures this out please let me know.


  • Dave

“Daily Notes” is one of the core plugs.
You turn it on and tell it where to find the template.

The name of the note is the date and then in the template I have:

{{title}} {{date:dddd}}

Because the date is the name/title of the file the {{title}} variable displays the date in YYYY-MM-DD format. The second variable, {{date:dddd}} displays the day of the week.

If you go into “core plug-ins” then “daily notes” and then click on the tiny configuration gear, the last option is:

Open daily note on startup
Open your daily note automatically whenever you open this vault.

Does that option do what you want?

Daily note creates the note for the date using the template you specify and you can choose to have the daily note automatically displayed when you open the vault.

There is also this note from osgav:

The Daily Notes plugin does not use the default {{date}} token from the Templates plugin. You need to specify the format. This will work → {{date:YY-MM-DD}}
{{date}} variable in Daily Notes plugin - #2 by osgav

This blog post may also be helpful.

Oh, thanks - I never thought there’d be a plugin. I assume if the note already exists it would just pull up that one, right?

I’m also wondering if it works as part of a specific workspace layout…

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