How to show all notes that filename begins with the current date (or is in the current calendar week)

I have notes with these names:

2023-08-26__0730-0815__KW34__HH22AB__INF__R304.md
2023-08-26__0920-1055__KW34__HH23C__INF__R304.md

I have this dataview:

TABLE
FROM ""
WHERE contains(file.name, date(today).format("YYYY-MM-DD"))

I want to show the notes as a result, but I get this error

Dataview: Every row during operation 'where' failed with an error; first 3:

                - Cannot call type 'null' as a function
- Cannot call type 'null' as a function
- Cannot call type 'null' as a function

How can I show all files with dataview, which begin with the current date?


What I’ve tried:

This works:

WHERE startswith(file.name, date(today).year + "-" + "08" + "-" + date(today).day + "__")

But not this:

WHERE startswith(file.name, date(today).year + "-" + date(today).month + "-" + date(today).day + "__")

This works for calendar weeks, but only with the file.day, not with the date in the file name:

TABLE 
FROM "BBZ/Schulisches mein eKb"
WHERE date(file.day).week < date(today).week + 1 AND date(file.day).week > date(today).week -1
SORT file.day desc

This gives an error:

TABLE file.link
FROM "BBZ/Schulisches mein eKb"
WHERE date(file.name.substring(0, 10)).week == date(today).week
Dataview: Error: 
-- PARSING FAILED --------------------------------------------------

  1 | TABLE file.link
  2 | FROM "BBZ/Schulisches mein eKb"
> 3 | WHERE date(file.name.substring(0, 10)).week == date(today).week
    |                                              ^
  4 | 

Expected one of the following: 

'(', 'null', boolean, date, duration, file link, list ('[1, 2, 3]'), negated field, number, object ('{ a: 1, b: 2 }'), string, variable

= rather than = should be used to equation.

You may modify the following script to meet your need.

TABLE file.link
FROM "BBZ/Schulisches mein eKb"
WHERE date(file.name.substring(0, 10)).week = date(today).week

Thanks for your response.

I copied and pasted your code, but I get this error message:

Dataview: Every row during operation 'where' failed with an error; first 3:

                - string indexing requires a numeric index (string[index])
- string indexing requires a numeric index (string[index])
- string indexing requires a numeric index (string[index])

It does not work, even not in the sandbox:

Strange: When I do <Strg-e>, sometimes I see the code and the error message alternate, sometimes I see only the error code and sometimes I see only the dataview code:

At first, it seemed to depend on if I use <Strg-e> or use the mouse to click on the icons in the upper right of the note. But later I could not reproduce. Now I always see this error(?). It comes again, when I click in an other window (for example, Google Chrome),

I downloaded a new copy of Obsidian 1.3.7 and installed it - same result.

I guess, it has something to do with the = in dataview.

Obsidian 1.3.7
Installer 1.3.7
Windows 10
dataview 0.5.56

To let you easier reproduce, here are my files:

Schulisches mein eKb.zip (1.4 KB)

Does this work as you need?

  1. One file name updated to match today’s date
  2. Extra file added as a test file
  3. Extra folder added to match the full path

Note that file.day is an implicit field:

Available if a file has a date in its file name (yyyy-mm-dd or yyyymmdd ) or has a Date field/inline field.

EDIT: Updated the files to 28 August for you (today’s date):

BBZ.zip (5.9 KB)

Yesterday’s original image below.

```dataview
TABLE WITHOUT ID
file.link
FROM "BBZ/Schulisches mein eKb"
WHERE file.day = date(today)
WHERE file.name !=this.file.name
SORT file.name ASC
```

Sorry for the inconvinience. I thought file.name.substring may work, so I did not test it.

substring(file.name, 0, 10) will extract the first ten character, and turned by date() into a time object
dur(3 days) is a period objects, so (date(today) - dur(3 days)) means three days before today.

More action can be found in the official website of dataview, Functions - Dataview (blacksmithgu.github.io)

list 
from ""
WHERE date(substring(file.name, 0, 10)) > (date(today) - dur(3 days))
1 Like

Thank you very much for your explaination.

Solution

Filenames look like so:
2023-08-28__0920-1055__KW34__HH23C__INF__R304.md
The first 10 letters show a date.

Show files with the date of today in their names:

TABLE without id
file.link
FROM "BBZ/Schulisches mein eKb"
WHERE date(substring(file.name, 0, 10)) = (date(today))
sort file.name

Show files with a date out of the current calendar week (KW) in their names:

TABLE without id
file.link
FROM "BBZ/Schulisches mein eKb"
WHERE date(substring(file.name, 0, 10)) <= (date(eow)) AND date(substring(file.name, 0, 10)) >= (date(sow))
sort file.name

or more elegant:

TABLE without id
file.link
FROM "BBZ/Schulisches mein eKb"
WHERE date(substring(file.name, 0, 10)).weekyear = date(today).weekyear
sort file.name

And as a bonus, the calendar week:

week of year of current file name `="calendar week" + date(substring(this.file.name, 0, 10)).weekyear`
week of year of current file name `=date(substring(this.file.name, 0, 10)).weekyear`
locale current week of year: `=date(today).weekyear`

This one I really love. It always shows notes of the current week in the middle, the last week before and the next week after. (The current calendar week is 35.)

TABLE
rows.file.link AS "Files"
FROM "BBZ/Schulisches mein eKb"
WHERE date(substring(file.name, 0, 10)) >= (date(sow) - dur(1 week)) AND  date(substring(file.name, 0, 10)) <= (date(eow) + dur(1 week))
SORT file.name asc
GROUP BY dateformat(date(substring(file.name, 0, 10)), "WW") AS "calendar week"

Here is an other link for people (and my later me …), who have similar questions about durations, sow, eow, som, eom, soy, eoy … : Literals - Dataview

1 Like

Couple of other alternatives:

# day
```dataview
TABLE WITHOUT ID
file.link
FROM "BBZ/Schulisches mein eKb"
WHERE file.day = date(today)
WHERE file.name !=this.file.name
SORT file.name ASC
```

# week

```dataview
TABLE without id
file.link
FROM "BBZ/Schulisches mein eKb"
WHERE date(today).weekyear
SORT file.day ASC
```

Thank you very much.

Your solutions look after the file.day. When you copy, move or sync your notes between different file systems (Windows, Linux/Android, USB-Stick, …) it may be that this date changes unintentionally. I had this issue, when I had to reset a database on android smartphone because of syncing problems. That (and sorting by date) was the reason, why I prefered a solution in the filename.

Nevertheless, good solutions, which I added to my knowledge base. :wink:

1 Like

Hi

file.day is taken from a date written in a file name (or a specified date field in a note). It doesn’t change when moving or syncing—only if the user chooses to manually change the name of the file. As part of the file name (as in your examples) it can’t change unintentionally.

file.mday, file.mtime, file.cday, and file.ctime are susceptible in the ways you highlight.

In the end, it is exactly the same query of the same file name but uses the shorthand provided by the Dataview developer.

It is possible to sort the files:

  • SORT file.day ASC
  • SORT file.day DESC

Good to have options.

:+1:

Just for anyone else who wants to check the metadata fields available in a note:

date: `=date(today)`  
date and time: `=date(now)`  
file.cday: `=this.file.cday`  
file.ctime: `=this.file.ctime`  
file.mday: `=this.file.mday`  
file.mtime: `=this.file.mtime`  
==file.day==: `=this.file.day`

==`file.day` is taken from the immutable (unless changed by the user) file name.==
1 Like

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