Dataview strings of contains and !contains not working

I am trying to create an MOC for my daily notes and I have three dataview tables, one that shows the current week’s pages, one that shows the current month (not including the current week pages), and general archive that contains pages that are not in the current week and month.

I had two questions. Can I make the dataview automatically process the current weeks and months, or do I have to go in weekly/monthy to change the week number and Month in the code? Second, In my month view I put in !contains(week, 38) but it does not remove those notes with that value in their YAML. Same happens in the archive, but the !contains(month, "September") works so it does not display the notes from week 38 because they are also in September.

Here is what each dataview block looks like and what they are outputting.

TABLE date as Date, dayofweek as "Day of Week", week as Week, month as Month, year as Year From "00 - Inbox/Daily Notes" WHERE contains(type, [[Daily Notes]]) WHERE contains(week, 38) Sort date desc

TABLE date as Date, dayofweek as "Day of Week", week as Week, month as Month, year as Year From "00 - Inbox/Daily Notes" WHERE contains(month, "September") and !contains(week, "38") Sort date desc

TABLE date as Date, dayofweek as "Day of Week", week as Week, month as Month, year as Year From "00 - Inbox/Daily Notes" WHERE contains(type, [[Daily Notes]]) AND !contains(month, "September") AND !contains(week, "38") Sort date desc

(as mentioned above, this correctly shows nothing because I do not have any notes that are not from September, but if I remove the !contains(month, "September) it will show my notes because the !contains(week, 38) does not seem to work.

Thanks so much!

Many things to say… But I choose only two:
1 - If you use the title as a date in format “YYYY-MM-DD”, yaml fields as dayofweek:, week:, month:… are absolutely not necessary. You can get that values from the date in title. If you read the plugin docs you see the particularity of the implicit field Data Annotation - Dataview. This means you can “extract” a valid date format from the title and play with that, extracting the year, the month, the week-of-the-year, the week day, etc…
2 - You don’t show us your yaml syntax/format. Because that I don’t know if you write week: 38 or week: "38" (one is a number, other is a string). In the query, if you write contains(week, 38) you’re looking for a number; if contains(week, "38") you’re looking for a string.

Thanks. I removed the quotes from around the week and that worked. I have them in YAML as a number and not a string.

In terms of the implicit field, I did not see that before. Though I do not see how to extract things like the weekday, week, etc. from that information. I use templater to get those fields in my YAML using <%“__”) %> (with WW, MMMM, YYYY, dddd in the space. If there is an easier way to get that by just extracting from the, that would be amazing. I am also guessing that is how I can modify the dataview code blocks to tell it I want to include the current week’s pages only in the current week view, or the current month’s pages in the month view?

To test purposes, try this:

TABLE,,,, dateformat(, "MMMM")
FROM "00 - Inbox/Daily Notes"

using WHERE = date(today).weekyear, for example, you can filter only the daily notes for the current week of the year:

TABLE,,,, dateformat(, "MMMM")
FROM "00 - Inbox/Daily Notes"
WHERE = date(today).weekyear

or, to avoid daily notes from previous years

WHERE dateformat(, "yyyy-WW") = dateformat(date(today), "yyyy-WW")

(see dateformat tokens here: luxon/ at master · moment/luxon · GitHub)


Thank so much! Those are great! and if I wanted to show files from the same month would it be

I guess “” is an attempt to say month + year (because weekyear doesn’t give the week + year, but the number of the week of the year, different from week as week of the month). For that you need to use the dateformat() function solution. I already give you an example for “year + week-of-the-year” (dateformat(, "yyyy-WW")) and the link for all possible tokens. I think now it’s your time to search, explore and found.
If I give you a tailor-made solution you don’t learn anything! :slight_smile:

Here you can see all variations you can extract directly from a date:
date.year, date.month,, date.hour, date.minute, date.second, date.week, date.weekyear.

Of course you can use solutions as:

WHERE = date(today).year AND = date(today).month

But with dateformat() you can “build” the comparison with the wanted values from the date. For exemple, with dateformat(, "yyyy-WW") we can extract this type of format: 2022-38, i.e., year-week-of-the-year (because «yyyy» is the luxon token for the year and «WW» is the token for the week-of-the-year).

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