Using Template dates in Dataview query

What I’m trying to do

I have a weekly notes template with headings for each day of the week. The date for these headings is generated via templates date syntax, e.g.

#### {{monday:gggg-MM-DD ddd}}
#### {{tuesday:gggg-MM-DD ddd}}
#### {{wednesday:gggg-MM-DD ddd}}
... etc

Under each heading I am trying to have a Dataview block that pulls a listing of the notes modified on the date that each heading references.

Things I have tried

However this doesn’t seem to work (i.e. the query result set is always empty):

List FROM "" WHERE file.mday = date("{{tuesday:gggg-MM-DD}}") SORT file.mtime asc

Is the Dataview plugin executing before the template engine has a chance to insert the date? Or is there something else that I’m missing?

Be aware that queries will not work in the template source version. It’ll only work after you inserted/instantiated the note based upon that template.

With that in mind, how does the query look within your daily note currently?

I hadn’t tried using the Periodic Notes syntax ({{monday:gggg-MM-DD ddd}}) in conjunction with Dataview before, but it seems to work over here. In addition to what holroy said, maybe your query isn’t formatted correctly? Using this in a weekly template:

#### {{monday:gggg-MM-DD ddd}}

```dataview
List 
FROM "" 
WHERE file.mday = date("{{monday:gggg-MM-DD}}") 
SORT file.mtime asc
```

…and running the command Periodic notes: Open weekly note, I get an output of:

#### 2023-05-15 Mon

```dataview
List 
FROM "" 
WHERE file.mday = date("2023-05-15") 
SORT file.mtime asc
```

dataview


I was going to put this in another post (may still do), but seems relevant here. Not sure if you want to try something new, but I do something similar for daily and weekly notes using Templater and Dataview to list notes created that day, but is easily adjusted to notes changed.

I use gggg-MM-[W]ww for weeklies which gives me a weekly note of 2023-05-W20. Having the month in there helps at a quick glance. Without it, I was always - “now where is week 32 in the year??”

  • I have Periodic Notes create the weekly note with no template.
  • Then use Templater to insert the template I want to use that week. (This could be done in one step with Templater, but I prefer to insert the template manually.)

A snip of my weekly Templater template looks something like this:

## **Monday** [[<% tp.date.weekday("YYYY-MM-DD", 1) %>]]

- Changed today:
    ```dataview
    LIST 
    FROM "" 
    WHERE file.mday = date("<% tp.date.weekday("YYYY-MM-DD", 1) %>") 
    SORT file.mtime asc
    ```

## **Tuesday** [[<% tp.date.weekday("YYYY-MM-DD", 2) %>]]

- Changed today
    ```dataview
    LIST 
    FROM "" 
    WHERE file.mday = date("<% tp.date.weekday("YYYY-MM-DD", 2) %>") 
    SORT file.mtime asc
    ```

## **Wednesday** [[<% tp.date.weekday("YYYY-MM-DD", 3) %>]]

- Changed today
    ```dataview
    LIST 
    FROM "" 
    WHERE file.mday = date("<% tp.date.weekday("YYYY-MM-DD", 3) %>") 
    SORT file.mtime asc
    ```

Which gives me:

This is very helpful. The important part that I was missing is that the syntax I thought was Templater date syntax belongs in fact to the Periodic Notes plugin and is only substituted when the note is created via that mechanism. Many thanks.

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