Get current week from file name - YYYY-MM-DD

What I’m trying to do

Essentially I want to use the file title in my daily note - YYYY-MM-DD to get the “Weekly goals” from that relative current week. I managed to get most of it but now it shows me all the weeks from the folder, I just want the current week with respect to the date from the file title.

Things I have tried

LIST rows.L.text
WHERE file.lists 
FLATTEN file.lists as L 
WHERE meta(L.section).subpath = "Weekly Goals" 
and contains(file.path, "Log/02-Weekly")
GROUP BY file.name

This gets me every week from my folder - 02-weekly in Log
and what I really want is the W-04 as seen below

I also tried to add the conditonal check of file name matches this week name - not sure if im doing it right!

LIST rows.L.text
WHERE file.lists 
FLATTEN file.lists as L 
WHERE meta(L.section).subpath = "Weekly Goals" 
and contains(file.path, "Log/02-Weekly")
and contains(file.name, dateformat(this.file.name, 'gggg-[W]ww'))
GROUP BY file.name

Any help would be appreciated!

What is the name of the weekly note?

You should be able to get the week out of the daily note using dateformat(file.day, "gggg-[W]ww") if that dateformat is correct.

Thanks for you rprompt response !
Weeks are labelled 2024-W01 etc - I use templater to create
" let weekLink = fileDate.format(‘gggg-[W]ww’); -%> "

I tried ```dataview
LIST rows.L.text
WHERE file.lists
FLATTEN file.lists as L
WHERE meta(L.section).subpath = “Weekly Goals”
and contains(file.path, “Log/02-Weekly”)
and contains(file.name, dateformat(file.day, “gggg-[W]ww”))
GROUP BY file.name

but got no results :(

There are some stuff which needs to be clarified, and just as @Koen did in a few very recent posts you need to use the correct date tokens in the respective environments. This means you need to translate the gggg-[W]ww from Templater which uses moment tokens, into something that dataview which uses Luxon tokens understand.

And you should most likely use this.file.name when you compare against the week formatted version of file.day. So maybe, if the weekly note is named according to your weekLink the following would work:

and this.file.name = dateformat(file.day, "yyyy-'W'WW")

ahh that makes sense, totally assumed dataview uses moment formating too. I did try the following

LIST rows.L.text
WHERE file.lists 
FLATTEN file.lists as L 
WHERE meta(L.section).subpath = "Weekly Goals" 
and contains(file.path, "Log/02-Weekly")
and this.file.name = dateformat(file.day, "yyyy-'W'WW")
GROUP BY file.name

But this gave me no results. I am making this query in the file titled “2024-01-08”. I have a week file called “2024-W02” that was created using the calender plugin while clicking on the week number on the side bar. That’s the week of this day that I wish to fetch. Is there any way to get that?

It’s close to the same, just the other way around… :slight_smile:

and file.name = dateformat(this.file.day, "yyyy-'W'WW")

But you had me kind of confused on the logic of your query. Is it correct that you want to lift the goals of the weekly note into the daily note? I would then order the query slightly different in order to quicker and with less work get it done:

```dataview
LIST rows.item.text
FROM "Log/02-Weekly"
WHERE file.name = dateformat(this.file.day, "yyyy-'W'WW")
  AND file.lists
FLATTEN file.lists as item
WHERE meta(item.section).subpath = "Weekly Goals"
GROUP BY file.link
```

Or if you don’t care about the link back to the weekly note:

```dataview
LIST WITHOUT ID item.text
FROM "Log/02-Weekly"
WHERE file.name = dateformat(this.file.day, "yyyy-'W'WW")
  AND file.lists
FLATTEN file.lists as item
WHERE meta(item.section).subpath = "Weekly Goals"
```

Both of these queries have the strong advantage that they don’t address any files outside of “Log/02-Weekly”, and they don’t expand any lists outside of those in the weekly note that we’re interested in. The order of business can be crucial in order to lower the amount of work to be done, which in turns increases efficiency.

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