Dataview Query Frontmatter Date + Math Calculation

Hi all. I’m hoping I can get some help with a data view query involving calculating dates from YAML Frontmatter

What I’m trying to do

A bit of background:
I have a note for business contacts, where each note has a YAML front matter tag for date when I last sent an email to said contact.

In my notes, I call that date a “sendout”, in the front matter a contact who I emailed on today’s date would appear as:


sendout: 2023-07-03

The dates do not correspond with the creation of the note, it is manually inputted from my emails.

What id like to do, is show a data view table that shows only contacts who’s send-out date is older than 2 months ago (updating in accordance with the current date).

In other words, show only contacts who I emailed 2 months ago or more.

I understand this would involve some kind of variable in addition to the date, however I am new to the program

Things I have tried

I’ve not tried anything yet (I am new to the program and this kind of math is over my head)

Here is an example of my data view table, that pulls from my folders named “Editorial Contacts” and the subfolder “Sendouts”

Table publication, sendout
From "Editorial Contacts/Sendouts"
SORT default(sendout, "") desc
```dataviewjs
let today = dv.date("today")
//convert two months to milliseconds
const twoMonths = 5184000000 
const table = dv.markdownTable(["File", "Sendout Date"], dv.pages("'Editorial Contacts/Sendouts'") 
	.sort(b => b.sendout)
	.where(b => today - b.sendout > twoMonths)
    .map(b => [b.file.link, b.sendout]))
dv.paragraph(table);
1 Like

To do this without JavaScript (dataviewjs):

> 3 months ago

TABLE publication, sendout, date(today) - sendout AS lapsed
FROM "Editorial Contacts/Sendouts"
WHERE dur(date(today) - sendout) > dur("3 months")
SORT default(sendout, "") desc

>= 3 months ago

TABLE publication, sendout, date(today) - sendout AS lapsed
FROM "Editorial Contacts/Sendouts"
WHERE dur(date(today) - sendout) >= dur("3 months")
SORT default(sendout, "") desc

All

TABLE publication, sendout, date(today) - sendout AS lapsed
FROM "Editorial Contacts/Sendouts"
SORT default(sendout, "") desc

YAML Example

---
sendout: 2023-07-03
publication: foo
---

In my test vault gives this:

Note: to see that == to 3 months make sure one of your dates is exactly 3 months ago.

2 Likes

Thanks so much tekiegirl, I appreciate it! This worked flawlessly

1 Like

Thanks! Unfortunately even when I turned on the javascript for data view, I couldn’t figure out how to get your code to work (it only showed as blank when I went into read mode)

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