[DataviewJS] Filtering query using dates

Hello everyone, I think I am missing something…I wrote three dataviewjs queries to group up meeting notes: “Past Meetings”, “Upcoming Meetings” and “Today’s Meetings”.

This is the query I use for “Past Meetings” that works:

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

dv.table(['Meeting', 'Type', 'Attendees', 'Date'],
	dv.pages('')
	.where(p => p.fileClass == 'meeting')
	.where(p => p.date < dv.date('today'))
	.filter(p => !p.file.path.includes('Templates'))
	.filter(p => !p.file.path.includes('Classes'))
	.map(p => [
		p.file.link,
		f(dv, p, "type"),
		f(dv, p, "attendees"),
		f(dv, p, "date")
	])
)

I wrote the same thing for “Upcoming Meetings” by changing the following line and it works:

.where(p => p.date > dv.date('today'))

The problem is for “Today’s Meetings”. I tried by changing the same line as the following:

.where(p => p.date == dv.date('today'))

But it doesn’t work. Any ideas??

Thank you!

Sadly dv.date('today') != dv.date('today') by some reasoning, and you’ll need to do: dv.date('today').ts = dv.date('today').ts. In other words when comparing for equality you need to use the .ts version of a date.

In your case that would amount to: p.date.ts == dv.date('today').ts and this statement might break due to a potentially mussing date field so I would use thif next version to counter that: p.date?.ts == dv.date('today').ts

For some more details see thread below:

That’s perfect! Thank you holroy!

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