I use a property week: 2024-01 in my daily notes and tried to filter a Table of files with them
TABLE Gottesthema, Herzthema, Meditation
FROM "Calendar"
WHERE week = "2024-01"
but it gave nothing back. What did I wrong?
I use a property week: 2024-01 in my daily notes and tried to filter a Table of files with them
TABLE Gottesthema, Herzthema, Meditation
FROM "Calendar"
WHERE week = "2024-01"
but it gave nothing back. What did I wrong?
I don’t know much about dataview but I think the dash is messing up with the dataview query. I tested it and it worked by removing the dash, and just making the date written as “202401”.
Using that format is understood by dataview as a date, or more specific as the combination of year and month. See date.
The proper way to indicate the year/week combo is to use 2024-W01
. This is unique and it follows the ISO 8601 standard.
Great solutions - I solved it with date(“2024-01”). Thanks for your help.
Ehh… That’s not a solution, that’s a workaround that depending on how you set your week-number property in the first place, and will most likely break in a few weeks. What happens with your solution when you get to week 13?!
In my special situation I use in my daily notes in properties the templater formula:
<% tp.date.now(“GGGG-WW”, 0, tp.file.title, “YYYY-MM-DD”) %>. That should work the whole year and in any situation, where I need this informations. Am I right?
No, since your query will then try to do date("2024-13")
, and there isn’t 13 months in the year, and it’ll fail.
You should change the Templater date format to become GGGG-[W]WW
, and a potential dataview date format to become yyyy-'W'WW
so that your query will work the entire year.
In your case where you compare against it as a text value, which is a valid approach with the Templater change, your query now becomes:
```dataview
TABLE Gottesthema, Herzthema, Meditation
FROM "Calendar"
WHERE week = "2024-W01"
```
This could possibly be enhanced even more, depending on where you’re using this query and which date variables are available in that context. Like if you are running the query from within a weekly note where the current week is stored as the week
property, and the file.day
is set from your daily notes (as either part of the file title or as the date
property):
```dataview
TABLE Gottesthema, Herzthema, Meditation
FROM "Calendar"
WHERE this.week = dateformat(file.day, "yyyy-'W'WW")
```
That’s really great - thank you! I changed the templates and periodic notes format to the standard as you said. I‘m a bloody beginner and I barely understand what I do here but learn a lot from your answers and trying to bring it in my vault.
But how do I have to change <% tp.date.now(“GGGG-WW”, 0, tp.file.title, “YYYY-MM-DD”) %> that sets me the week property in my daily note template?
And how do I have to set the week property in the weekly template so that these variables will be set right, even when I create the week note in another week, and the daily note on another day?
After setting the variables right I should be able to use your dataview queries to work with the week property as base, am I right?
Thanks in advance, Fred
In the daily note template change it to:
<% tp.date.now("GGGG-[W]WW", 0, tp.file.title, "YYYY-MM-DD") %>
I’d be lazy and use a similar approach in the weekly note, something like:
<% tp.date.now("GGGG-[W]WW") %>
This will produce the wrong value of you create it on the wrong week, but I reckon it’s easier to add/subtract from the result since you do know if you created the weekly note to early or to late.
Given a week
property in both the weekly note, and the daily note your query of related notes from within your weekly note could then become:
```dataview
LIST
WHERE week = this.week
```
Great - that worked like a charm. Thank you very very much!!!
Is it possible to bring the weeks together to a month for queries in the monthly note? Or would it be easier to use the daily note names (YYYY-MM-DD_ddd) as Input for the query?
In a monthly query I would reuse the date of the daily month, in something like:
```dataview
LIST
WHERE this.month = dateformat(file.day, "yyyy-MM")
```
Which depends on a property in the monthly file called month
set to a value like “2024-01”. That way you wouldn’t need to change anything in the daily notes, just maybe a slight change to the monthly note.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.