I’m trying to filter the task lists in my daily journals from the last 7 days. However, Whatever command I’m trying in DataviewJS, I can’t get it working.
My daily journal filenames are formatted like ‘YYYY-MM-DD-ddd’ (e.g. ‘2022-03-8-Tue’). In each file, I have some tasks and I only want to filter tasks that do not contain ‘#tag1’ and ‘#tag2’.
Here is my dataviewjs code snippet. I need help in Line 3 of the code snippet (where( p => ....)
Is dv.date(p.file.name) correct in converting ‘2022-03-08-Tue’ to a date object?
How can I get today’s date (should replace TODAY in the code snippet below) in DataviewJS?
Was able to achieve that by defining JS variable for today, like below
const now = new Date(Date.now());
// toISOString() will return something like '2022-03-20T19:07:16.493Z' and I only need the first 10 characters
const today_date = dv.date(now.toISOString().slice(0, 10))
dv.taskList(
dv.pages('"01 Journal"')
.where(p => (dv.date(p.file.name.slice(0,-4)) >= (today_date - dv.duration('7 days'))))
.sort(p => p.file.name, 'desc')
.file.tasks
.where(t => !t.text.includes("#tag1"))
.where(t => !t.text.includes("#tag2"))
I’m a DQL guy, so I’m not able to help in js (in particular about dates). But I have a suggestion: instead of dv.date(p.file.name) why you don’t use p.file.day? file.day is an implicit field for notes with the title in the format (parcial or total) “WWW-DD-MM”. https://blacksmithgu.github.io/obsidian-dataview/data-annotation/#implicit-fields
With file.day you get an extracted date value (don’t need to add date prefix neither use the slice() method).