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 file.day: 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 <% tp.date.now(“__”) %> (with WW, MMMM, YYYY, dddd in the space. If there is an easier way to get that by just extracting from the file.day, 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?

using file.day
To test purposes, try this:

TABLE file.day.year, file.day.month, file.day.weekyear, file.day.week, dateformat(file.day, "MMMM")
FROM "00 - Inbox/Daily Notes"

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

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

or, to avoid daily notes from previous years

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

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

1 Like

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

I guess “file.day.monthyear” 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(file.day, "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.day, date.hour, date.minute, date.second, date.week, date.weekyear.
https://blacksmithgu.github.io/obsidian-dataview/query/expressions/

Of course you can use solutions as:

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

But with dateformat() you can “build” the comparison with the wanted values from the date. For exemple, with dateformat(file.day, "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).