Creating dataviewjs table in daily note using daily note name as value in WHERE

Things I have tried

Block is in daily note template. Result displays all #task files without WHERE line in query; displays no results for table query when including WHERE line as shown:

const {update} = this.app.plugins.plugins["metaedit"].api
const {createButton} = app.plugins.plugins["buttons"]

dv.table(["Begin", "End", "Event", "Description", ""], dv.pages("#task")
    .sort(t => t.tbegin, 'asc')
    .where(t => t.taskdate == dv.current().file.name)
    .map(t => [t.tbegin, t.tend, t.file.link, t.description, 
    createButton({app, el: this.container, args: {name: "Done"}, clickOverride: {click: update, params: ['status', 'done', t.file.path]}})])
    )

There is sample task file with proper metadata

What I’m trying to do

I trying have a simple table displaying task files (I don’t use tick boxes) in table view on my daily note. Each task file has inline taskdate:: YYYY-MM-DD format. Each daily note is named simply YYYY-MM-DD according to the current day.

Syntax work perfectly with other templates to call documents based on current file name, example:

dv.table(["Title", "Published", "Pages"], dv.pages()
.sort(t => t.year, 'asc')
.where(t => t.author == dv.current().file.name)
.map(t => [t.file.link, t.year, t.pages]))

What wrong with using .where(t => t.taskdate == dv.current().file.name) for tasks above? Something with date instead of string? Solution in dataviewjs, I like button complete feature instead of box

This has confuddled me a bit… I thought the answer was easy, you just need to coerce your file name into a DateTime object like so:

const today = dv.date(dv.current().file.name)

And then simply use that in the equality comparison. However in my testing this didn’t give any results. However, I did get it to work with GTE and LTE like so:

// fails
...
  .where (t => t.taskdate == today)

//succeeds??
...
  .where(t => t.taskdate >= today && t.taskdate <= today)

See if going for the combined comparison works for your use case, and then if anyone else can shed some light on why the equality check isn’t working I’d be interested in that!

Dates in JS are a ****.
Try something like

...
.where(t => t.taskdate?.toISODate == dv.current().file.day.toISODate)
...

Thank for your help. You are right this is confuddle. I tried variations:

const today = dv.date(dv.current().file.name)
.where (t => t.taskdate == today)

result: no results

const today = dv.date(dv.current().file.name)
.where(t => t.taskdate >= today && t.taskdate <= today)

result: no results

.where(t => t.taskdate?.toISODate == dv.current().file.day.toISODate)

result: no results

.where(t => t.taskdate?.toISODate == dv.current().file.day.toISODate)

result: no results

.where(t => t.taskdate.toISODate == dv.current().file.day.toISODate)

result: Evaluation Error: TypeError: Cannot read properties of undefined (reading ‘toISODate’)

.where(t => t.taskdate?.toISODate == dv.current().file.name.toISODate)

result: shows all tasks files including template, not just specific for current daily note

.where(t => t.taskdate.toISODate == dv.current().file.name.toISODate)

result: Evaluation Error: TypeError: Cannot read properties of undefined (reading ‘toISODate’)

I don’t know if you ever got to the bottom of it, but on a snowy afternoon in Whistler I’ve come up with this for pure files (not tasks, but hopefully it will get you an inch further on). My daily notes are named in “YYYY-MM-DD” format:

Notes created today:

const thisDay = dv.current().file.name;

dv.list(dv.pages("").where(f => DateTime.fromMillis(f.file.ctime.ts).startOf("day").toISODate() == thisDay).limit(100).file.link)

Notes modified today:

const thisDay = dv.current().file.name;

dv.list(dv.pages("").where(f => DateTime.fromMillis(f.file.mtime.ts).startOf("day").toISODate() == thisDay).limit(100).sort(f => f.file.mtime, "desc").file.link)

I put a large limit in there since I don’t want to actually restrict it currently but maybe I will in the future.

Thanks for the pointers that got me to this baroque incantation.

Also, for what it’s worth, I hate JS. Give me a nice solid Elixir/Erlang platform :).

what about something similar to:

.where(t => t.file.mday.ts == dv.current().file.day.ts)

That’s definitely interesting. I’ll need to check if it works with daily notes that are created on a different day to their filename (which happens if I create a note in advance, for example). Thanks. Brain switched off for today, but I’ll tweak my query to use the .mday. field to at least shorten things a little.

file.day is different from file.cday.
file.day is an implicit data if you have a file name with the format “YYYY-MM-DD” (full name or part of the name) or a date: field in your note. Dataview take that values as dates.

1 Like

Awesome, perfect and considerably less baroque.

1 Like