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

Hello, I’m new to Obsidian and have no programming experience.

I would like to list files with Dataview plugin where the all files of the same day in other years are listed. Filenames have the format YYYY-MM-DD.

So for instance today 2021-08-26, I would like to list files of 2020-08-26, 2019-08-26, etc

Could anyone help me on this?

Things I have tried

What I’m trying to do

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


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:

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:

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:

    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.

Thanks a lot for the quick reply! I’ll give it a try :smiley:

1 Like

Let us know the outcome! :slight_smile:

It works perfectly, thanks a lot :smiley: !

1 Like

Glad I could help! Just remember if you want to exclude the current year, add the part I mentioned somewhere (comparing year). So you’d effectively get a “On this day in history” :wink:

1 Like

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