How can I use dataview to automatically return the current week?

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

I want to write a simple query that would link to current week.

Things I have tried

searched the forum and dataview documentaion

Something along the lines of this, perhaps?

```dataview
LIST
WHERE file.cday > date(today) - dur(7 day)
LIMIT 50
```

thanks for responding.
If I read this correctly, this query all the notes created during the current week.

Is there a way to just output the current week?

I can get there by filtering the file.name, at this point is more of an intellectual curiosity than anything else

I know you asked for dataview, but here is the logic to this with templater (and also grab the previous/next week):

<%*


  week_date_format = "GGGG [Week ]ww"
  day_date_format = "YYYY-MM-DD"

  week = tp.date.now(week_date_format)
  wk_start = tp.date.weekday(day_date_format, 0)
  wk_end = tp.date.weekday(day_date_format, 6)
  let title = `${week} (${wk_start} -- ${wk_end})`

  pweek = tp.date.now(week_date_format, -7)
  pwk_start = tp.date.weekday(day_date_format, -7)
  pwk_end = tp.date.weekday(day_date_format, -1)
  pwk_title = `${pweek} (${pwk_start} -- ${pwk_end})`

  nweek = tp.date.now(week_date_format, +7)
  nwk_start = tp.date.weekday(day_date_format, +7)
  nwk_end = tp.date.weekday(day_date_format, +13)
  nwk_title = `${nweek} (${nwk_start} -- ${nwk_end})`

-%>

Since dataview uses the same moment.js under the hood, this should be easy to adapt for dataview.

1 Like

thank you, will save this for later. haven’t learned templater yet

Hi @paoloap ,

Could you share an example of what output you’re expecting? Do you have a “week page” that you’re trying to link to? If so, what is the format of the page’s name?

One way to do this, if you want it as a link to a weekly note could be:

`= dateformat(date(now), "'[['yyyy'-W'WW']]'")` 

If you don’t want it as a link, just remove the brackets (and single straight quotes). If you just want the week number change the format accordingly to your needs. See dataview’s dateformat for documentation, and luxon tokens for dateformat token.

2 Likes

fantastic @holroy.

I wonder, how can this work withotu rhe dataview enclosing?

What do you mean? That is an inline dataview query, which makes it work.

If not using dataview, there exist some solutions as indicating in other posts related to Templater, or other template engines. And you could most likely get quick at to do something similar, but I kind of like dataview, so that’s my default answer…

1 Like

clear. I’m not familiar with inline dataview, only with the canonical

‘’’ dataview

‘’’

1 Like

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