DataviewJS get files matching same date as note's title

What I’m trying to do

Hi everyone. I am trying to make a table in my daily note that lists all other notes scheduled on that same day, so there is a link to them and a little check-box.

For this, the metadata field with the date is called “fc-date” and the query can simply search for the name of the daily note since its name is just the date written in the exact same format.


const {fieldModifier: f} = this.app.plugins.plugins["metadata-menu"].api; 

dv.table(["File Name", "Shared"],

await Promise.all(dv.pages('"Social Media Activities"')
	.where(p => p['fc-date'] == "this.file.name")
    .map(async p => [
      p.file.link,
      await f(dv, p, "shared"),
	])
))

Things I have tried

I’ve tried lots of little variations of this code but either the table pulls all files in the folder, or doesn’t pull anything.

Within dataviewjs you can’t use this.file.name, you need to do something like dv.current().file.name.

I’ve done, like, this for example. I’ve been able to sort the files (for example, list everything before or after the date) but I haven’t been able to get it to just pull files matching the date.


const noteDate = '2023-12-14'
const { fieldModifier: f } = this.app.plugins.plugins["metadata-menu"].api;

dv.table(["File Name", "Shared"],
  await Promise.all(
    dv.pages('"FCE"')
      .where(p => p['fc-date'] == dv.date(noteDate))
      .map(async p => [
        p.file.link,
        await f(dv, p, "shared")
	])
))

With this, for example, I can get part of the list to pull. But I’m not sure what to do to make it just pull the file with the correct date. I don’t really do much programming or anything so I’m not really familiar with javascript.


const noteDate = '2023-12-14'
const { fieldModifier: f } = this.app.plugins.plugins["metadata-menu"].api;

dv.table(["File Name", "Shared"],
  await Promise.all(
    dv.pages('"Z. Google Shared Folder/FCE"')
	  .where(p => p['fc-date'] >= dv.date(noteDate))
      .map(async p => [
        p.file.link,
        await f(dv, p, "shared")
	])
))

So I ended up hoping in the discord, and one of the wizards did their magic! After some troubleshooting we ended up with this:

const { fieldModifier: f } = this.app.plugins.plugins["metadata-menu"].api;

dv.table(["File Name", "Shared"],
  await Promise.all(
    dv.pages('"Social Media Activities"')
      .where(p => p['fc-date']?.toFormat("yyyy-MM-dd") == dv.current().file.day.toFormat("yyyy-MM-dd"))
      .map(async p => [
        p.file.link,
        await f(dv, p, "shared")
    ])
))

For some reason using only
.where(p => p[‘fc-date’] == dv.date(noteDate))
or
.where(p => p[‘fc-date’] == dv.current().file.name)
refused to work.

As you’ve discovered dv.date("today") == dv.date("today") is not true, which is kind of a bummer, and you need to do either dv.date("today").ts == dv.date("today").ts to get it to be equal, or do the dv.date("today").toFormat("yyyy-MM-dd") == dv.date("today).toFormat("yyyy-MM-dd") which you’ve opted for.

The first of this format is slightly better, but both can be used, when comparing against date ranges.

For a lengthy post on the ickyness of dates see link below:

1 Like

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