Can I pass dates to a dataview query?

What I’m trying to do

I have a dataview query to help me list all bullet points in my daily notes over seven days each week.

TABLE without ID AS Date, file.lists.text AS Highlights
from "Journal/Daily"
WHERE >= date(2023-04-10) and <= date(2023-04-16)

Is there a way to put the two dates, that I change every week, somewhere else in the note so that I don’t have to edit the dataview query directly every time?

Does it work as you need with ‘start of week’ and ‘end of week’ parameters?

TABLE without ID AS Date, file.lists.text AS Highlights
from "Journal/Daily"
WHERE >= date(sow) and <= date(eow)

You could try the technique I outlined here: Filterable Dataview Table / Change Work Mode / Filter Note List. I think it will get you there.

I didn’t know about these parameters. It would work if it could be modified to refer to the previous week’s dates as I usually do my weekly review on the Monday following the week that interests me.

Where will you be using this query? In each of the daily notes, or just the weekly review or something similar?

Multiple options are available related to how not to hardcode the dates within the query.

Use a frontmatter field

You could declare the wanted dates within the frontmatter:

weekStart: 2023-04-10
weekEnd: 2023-04-16

TABLE without ID AS Date, file.lists.text AS Highlights
from "Journal/Daily"
WHERE >= date(this.weekStart)
  AND <= date(this.weekEnd)

Date manipulation

If you’re using Templater you can rather easily find the start and/or end of week when you create your daily/weekly notes.

The same can be done within the Dataview query, where one way of doing it would be to use duration calculation related to your current date. The following example should show the way of doing this:

  (D - dur(D.weekday + " day")), 
  (D - dur((D.weekday - 6) + " day")) 
  "2023-04-18" ) as testDate
FLATTEN date(testDate) as D
WHERE file.path = this.file.path

Which produce this output:

In the output you’ll see that it can correctly subtract days across month, and get you the correct week start and ends

So if you do ( - dur( + " day")) given that you’re either using filenames or fields defining the date, you should get the start of that week. For the end of the week (since we’re basically subtracting to start with): ( - dur(( - 6) + " day")).

Note that using date(sow) & co, will always refer to the current date (if I’m not mistaken). So whilst they are valid in the current weekly note, if you open that note in a few weeks, or you go back to a weekly note in the past, it’ll still use current date to calculate start and end of week. In many cases that is not what you intend for them to do.

1 Like

Thank you very much. A perfect solution. I was on the right track when I thought about a solution, but I didn’t know that I should use the “(this.weekStart)” and “(this.weekEnd)” construct.

I chose the frontmatter field method with the difference that I put the date fields in the body of my weekly review note with double colons. I use the note as a means to view the previous week’s daily notes’ highlights (bulleted items in each daily note) in an overview of the week. Reading this information I then create my weekly review proper note.

1 Like

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