How do you return the tasks that were completed on the date associated with a file?

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

In dataviewjs I simply want to return the tasks whose completion date matches the date associated with a file.

In plain old dataview it’s simple:

WHERE completion = date(

Things I have tried

dv.taskList(dv.pages().file.tasks.where(t => t.completion ==

Why isn’t his working?

A dataview query (or DQL query for short) and a dataviewjs query (or DVJS) uses different syntax. The latter uses javascript, and every variable and function needs to be references according to the rules of javascript. The former is a self-declared language, and it has loads of shortcuts to facilitate writing (somewhat) easy to read queries.

   .where( t => t.completion == )

Most of your issues are related to that last line with the .where-clause:

  • is not a known function to DVJS. To refer to the DQL function, you’d need to do
  • refers to something entirely different within javascript, which most likely isn’t defined in your context. The equivalent code would be something like dv.current() (In addition, if you want to do something equivalent to date(now) from DQL, you’d need to do date("now") in javascript to properly use the literal text as an argument)
  • Finally, there is some thingy within javascript that doesn’t allow for equality tests. Two ways to address this is to either convert the dates into strings using something like .toFormat("YYYY-MM-DD") or to pick out the timestamp values using .ts. (Strangely enough, before/after works, but its just the equality which fails)

Accounting for all of the above, we end up with something like:

const thisDay = dv.current() )

  .where( t => t.completion && t.completion.ts == thisDay.ts ))

In addition to the comments above, I’ve also extracted the calculation of the current date into a separate variable, so we don’t need to do that for each and every task we’re querying upon.

You’re wizard @holroy!


Thank you for breaking down the code and explaining so thoroughly!

Thank you so much!

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