How can I make a dataview query that shows incomplete tasks in all of my daily notes?

I looked the documentation for task queries and came up with this one:

WHERE !completed AND !checked
SORT asc

But I want it to only show tasks specified in daily notes. I did a bunch of googling for this but haven’t found anything promising. Idk if this would help but I’m trying to switch from queries made with the tasks plugin. Here’s my current tasks query:

filename regex matches /\d\d\d\d-\d\d-\d\d January|February|March|April|May|June|July|August|September|October|November|December/
status.type is TODO
sort by filename reverse

This is filename format I specified in the Daily Notes core plugin: YYYY-MM-DD MMMM Do YYYY dddd. Which looks like this: 2023-05-02 May 2nd 2023 Tuesday.

As the daily notes core plugin relies on a specified folder for daily notes, I suppose all your daily notes are located within the same folder.

Thus your query would be:

FROM "folder"
WHERE !completed AND !checked
SORT asc

Just replace folder with the name of your daily notes folder.

@alltagsverstand I found an answer here which works and I changed it to this:

FROM "" WHERE !completed AND !checked AND
regextest("\d\d\d\d-\d\d-\d\d January|February|March|April|May|June|July|August|September|October|November|December",
SORT desc
  • However, I’m having trouble sorting it, specifying asc or desc, I want to have it sorted by latest date to earliest date.
  • Also, when I group by name, it shows then has 4th level headings / h4s. Do you know how I can make them show as regular text?

The regex you provide related to the Tasks plugin seems to be less than ideal: /\d\d\d\d-\d\d-\d\d January|February|March|April|May|June|July|August|September|October|November|December/. If I’m not mistaken this will give a positive match on all of the following:

  • 2023-12-01 January
  • February
  • March
  • … and so on

What I’m trying to say is that the alternation character, if I’m not mistaken, will be on everything from the / or previous | to the next the | or /. If you wanted to actually have a match against the date for all month, you could need to group the last part, so maybe something like:

/\d\d\d\d-\d\d-\d\d (January|February|March|April|May|June|July|August|September|October|November|December)/

However, that doesn’t seem to be your main issue as you want to start using a Dataview query. The similar regex for dataview would look like:

 regextest("^\d\d\d\d-\d\d-\d\d (January|February|March|April|May|June|July|August|September|October|November|December)", filename)

Note that using regextest() does a partial match on its variables, whilst regexmatch() must match on the entire string.

Examples using this regex

Put the following in a note, and check the result (or play around with similar test cases added to the list()

TABLE WITHOUT ID filename, matches

 "2023-01-03 January 1st",
 "Ooopsie, 2023-03-03 March 3rd",
 "2023-05-03 May 3rd",
 "9999-99-99 December 99th?") as filename
  regextest("^\d\d\d\d-\d\d-\d\d (January|February|March|April|May|June|July|August|September|October|November|December)", filename) as matches 

WHERE file.path = this.file.path

Another question related to your Tasks query, what is included in your status.type is TODO? Only - [ ] or also - [/], any other status variants?

Assuming only those two we’re now at query looking like this:

WHERE regextest("^\d\d\d\d-\d\d-\d\d (January|February|March|April|May|June|July|August|September|October|November|December)",
WHERE contains(list(" ", "/"), status)
SORT key desc

Does that resemble what you want out of the query?

Note the trick on doing SORT key after the GROUP BY clause.

@holroy The regex in both that tasks query and the one I had in that DV query worked fine for matching my daily notes. Its just that issue was not being to sort them. Do you think the regex got in the way of that? I don’t think so.

Anyway, that last query you provided does successfully sort them by descending date.

Now the last thing I’m wondering, how can I make the group headers appear as regular text (or however I want it to) instead of as 4th level headings / h4s?

I’m not saying it wasn’t working fine, but it was a little too open. So if you had made a note like Freedom March or May the Force be with you, they would also be recognised as daily notes. Would it affect sorting, not per se, but it could cause some anomalies here and there…

I don’t think that’s something you can easily change as long as you’re using a DQL query. One option could be to change to a dataviewjs query, and insert the text in between the groups yourself, but it would require a little bit of code fiddling.

Another option, which might be helpful if you know a little CSS, is to add a tag to help you target your CSS to these elements, and then style them to look however you’d want them to look. If you change the GROUP BY statement to something like:

GROUP BY "<mark class='taskGroup'></mark>" + 

You could target these lines using:

h4:has(.taskGroup) {
   /* Your CSS here */

You could also use similar tricks to change the text to match your preferences. Just make sure it doesn’t alter your sorting or grouping by having the extra text changing something it shouldn’t. :smiley:

Thanks for the solution! That’s what I went with days ago. Though, I found that I can use the has selector for the following classes if I want the CSS to only apply to task queries: .contains-task-list, .dataview.task-list-item, and a few others.

There is another thing I need help with though, I want to group the tasks by so I have a link to each page, but I struggled to get it in alphabetical order. I made a separate post for this, can you look at it? Thanks. In dataview, How can I group tasks in a task query by and make them show up in alphabetical order?.

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