Query Tasks completed today with DataviewJS

Query Tasks completed today with DataviewJS

Hi Everyone,

I’d like to track how many tasks are completed in a day, or maybe during a given period.

Things I have tried

To start simply, I’ve tried to make a script that calls all of the completed tasks today.
Heres the following DataviewJS script i’ve implmented:

let q = dv.pages()

	.sort(p => p.completion, 'desc')
	.filter(p => p.completion == dv.date('today'))
	, "")

This doesnt work, and just returns nothing.

I have done the equivalent in DQL, but im hoping for a DataviewJS solution, as i usually like to tap into its higher capabilities.

Any ideas or solutions?

1 Like

This doesn’t answer your question exactly, but it might spark an idea for you on how to proceed. On my dashboard, I like to list all the tasks I’ve done today. All my tasks live in my daily notes, which have file names like “20220617 Friday”. Here’s the code that pulls the completed ones for today:

`$=dv.header(3, "Things I've Done Today");dv.taskList(dv.pages('"Journal"').where(p => p.file.name == dv.luxon.DateTime.now().toFormat('yyyyMMdd cccc')).file.tasks.where(t => t.completed));`

Essentially, I’m choosing the file to pull the tasks from by reformatting today’s date to my daily note naming convention, and then matching on that. Like I said, I realize that probably doesn’t get you exactly where you need to go, but I hope it gives you at least something to work with.


@perpendie Do p.completion and dv.date('today') match exactly in date and time when they are supposed to match?
Maybe just for investigating what is going on make a table where you replace the .filter with a .limit(5) and display the completions in a column to make sure they look like what you expect in Javascript?

dv.table(['Comp. Date', 'Task Text'],
         q.file.tasks.sort(t => t.completion, 'desc')
         .map(t => [t.completion, t.text])

This is really neat, thank you for sharing!

1 Like

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