Query files of the same day in other years with Dataview plugin

Just compare if the month and day are the same, using a WHERE clause.

Example:

---
date: 2021-08-26
---

# Test Dataview - On this day

The search _excludes_ this note!

**For files having a "dated" note title** (like the _Daily Notes_), newest at top:

```dataview
LIST
WHERE file.day.month = date(today).month
    AND file.day.day = date(today).day
    AND file.path != this.file.path
SORT file.day desc
```

**For _any_ file having a _creation date_ like today**, newest at top:

```dataview
TABLE dateformat(file.cday, "yyyy-MM-dd") as "Created "
WHERE file.cday.month = date(today).month
    AND file.cday.day = date(today).day
    AND file.path != this.file.path
SORT file.cday desc
```

For performance reasons, if all files come from a defined folder (like “Daily Notes”), you might want to add that in a FROM clause below the LIST or TABLE line:

FROM "Daily Notes"

You could also add a “not from this year” exclusion clause to the WHERE:

WHERE …
    AND file.day.year != date(today).year

Some explanations:

  • file.day extracts the date from the file title or a date: variable given in the note’s YAML frontmatter.
  • file.cday is the creation date (no time).
  • file.mday would be the last modified date (again, no time)
  • All three have the methods .year, .month and .day to get the year, month and day, respectively.
  • yyyy-MM-dd (instead of YYYY-MM-DD) is just Dataview’s way of using a date formatter (it uses Luxon). Here is a list of allowed tokens.