Hi guys, I’m using Dataview to categorize my journaling notes by week, month, year, etc. I have weekly notes that I want to round up in Dataview with the field
month. The weekly note template that I use autofills the month for me (thanks to Templater) with the following line of code:
<% tp.date.now("YYYY-MM") %>
The problem is that Dataview is not picking up the correct months at all. When I use the following code to pull up what Dataview is reading in the
GROUP BY month
It only sees:
- <% tp.date.now(“YYYY-MM”) %>
I am expecting Dataview to return keys like
2022-07, I find it very odd that Dataview is picking up a month value of basically zero.
Things I have tried
In the weekly journaling notes, I’ve tried surrounding the month key in quotations and brackets. I’ve double-checked that there is exactly one space separating the colon (from the field name) and the key itself.
Thank you for your response! I was able to try your debugging code on my end. Here is how I paraphrased it:
TABLE WITHOUT ID
file.link AS "File",
month AS "S1_Month",
typeof(month) AS "S2_T_Month",
F_year_month AS "S3_year_month",
F_year_month2 AS "S4_year_month2"
FLATTEN dateformat(month, "yyyy-MM") AS F_year_month
FLATTEN dateformat(file.day, "yyyy-MM")
AS F_year_month2 SORT file.name ASC
Unfortunately, I didn’t get quite the same result as you. Specifically, the
dateformat(file.day, "yyyy-MM") returned null output. Do you know what might be going on? I’m using Dataview 0.5.41 and Obsidian 0.15.8.
Actually, I have a different, more specific concern than trying to replicate your results now.
I have this code that selects weekly journaling notes for the month of July 2022:
WHERE dateformat(month, "yyyy-MM") = "2022-07"
My new problem is that this code will not select weekly journaling notes that have two values for the
For example, I wrote
[2022-07, 2022-08] for the value of the
month key in the weekly note for Week 32 since it straddles across two months. The code above does not include this weekly note. (Furthermore, when I surround
2022-07 in brackets in weekly notes that are only part of July 2022, this Dataview code doesn’t select it. So I think Dataview is viewing it as an array that
dateformat cannot handle.) What code would also select the note for such note?
Excellent investigating here! Just to add on to what @justdoitcc has written, if you are trying to find something in a list, equality does not work, since the list does not equal one element of that list! Instead
contains(list, element) will test whether
element. Since your output is strings, and strings are lists of characters internally,
contains(dateformat(month...), "2022-07") should work regardless of whether
month is a list! If month is not a list, well, “2022-07” does contain “2022-07”!