Filter tasks based on (earlier than) today


I’m totally new to Obsidian (which is fantastic) and with little knowledge on programming. I would need help on tasks filtering based on a post in this forum by Nils:
var now = new Date();
var today = now.setHours(0,0,0,0);
.where(f => ( < today))
.sort(f =>
.tasks.where(t => !t.completed), true);

but none of the past (incomplete) tasks show up, presumably due to a date setting? As far as I understand does “” not correctly read the “time stamp” of the files/notes?

Any help very much appreciated, thank you!

First question to clarify: what’s your notes title? (in your js code is it’s an implicit field that identify a date in the title note. But that date need to be in the format “YYYY-MM-DD”.
For example:

  • 2022-03-01
  • 2022-02-23 Wed
  • 2022-02-03 My note
  • Other note 2021-12-27

ok, so my notes title is e.g. “2022-Mar-02”. How would I set this in the js block?

That is the problem: isn’t a valid format to work with metadata.
Isn’t an issue to be solved via code, need to be solved in the source, i.e., in your notes metadata.
If the date is the main issue, you have many ways:
1 - Change your files title to a recognized format;
2 - Create in each note a field with the date in the right format;
3 - Add to your tasks an inline field with date (one question: what’s the meaning of the date to your tasks? a due date? a creation date?)
4 - If the create date of your note is the same of the title note, use file.cday instead of

One last point. Using dataview implies some basic knowledge in the way that Obsidian works and the plugin itself. This doesn’t mean know how to construct a more complex queries. But I think it isn’t the right way try to achieve one goal without any idea of what is in stake. You can start here: Dataview

Hmm, so reverted the date format from YYYY-MMM-DD to YYYY-MM-DD in the Daily notes plugin …note title is now 2022-03-02 …and it works. But still would rather see the MMM format in the title.
The date is used to list the past tasks in chronological order including the note titles to see the date when the tasks were created. (as uploaded by Nils here)

Did you read any page of the plugin documentation?
Did you understand any of the 2, 3 and 4 points above?

You have your preferences, the plugin works under certain conditions. How to achieve a solution that consider both sides? You need to find a way accordingly the many resources that the tool (the plugin) offers you. (sometimes there’s no solution)

Why you use DVJS code instead of a more simple DQL query? I know something about dataview, but I know almost zero in JS.

As I said before (and believe it, I help many people in dataview questions), you need to do some approach to the tool: read the documentation, spend time to learn, etc. I can give you a solution. But what you learn with it? You want your goal, just that, without any understanding of the great tool you have in hands. You want a solution, just that?

Well, I did read quite a bit of the documention, and believe it or not, for a relatively new kid on the block (btw aged 58) it is not that exhaustive. Also, I did spent around 10 hours on that particular problem before asking a question here on the forum.
Technically, I thought I could assign the notes.title → to achiev what I thought might work using code pieces submitted by others. As mentioned Nils version, that has the problem that if you create a future daily note things get messed up, such as task with date < today are not shown.
And last comment: you may take into account that a large portion of the population wants to use a tool rather than designing it for ages…that’s what I tried to accomplish, i.e. adapt a very nice tool for my best liking resp. purposes (but not becoming a software developer).
Still, thanks for trying to point in the right direction.

I understand well your point! I don’t have any coding knowledge or similar and I’m not a young too. I’m a simple obsidian user helping others with the knowledge I acquired in using obsidian along a year.

The question here is: you don’t need to know code or similar, but you need to know how to write your notes (particularly the metadata) to work with the tool “dataview”. An example. If you read the documentation, you know that there’re implicit fields and the “created fields”, ie, the first are fields like “file name”, “creation date”, “modification date”, “file tags”, etc. (similar to the data you see in your system); the last are fields created using specific rules.

You said you can’t use the “creation date” because the daily notes created before the right date. So, if you have this habit and you don’t want to change your title format, then you need to think if it’s better create a field to define the right date.
You can create new fields via yaml frontmatter or inline. For now we can exemplify with a frontmatter field.
To add yaml frontmatter fields to your notes you need to write in the first lines of your notes (first lines, without anything before) something like this (3 dashes + fields + 3 dashes):

myfield: my value
note-date: 2022-03-02

In the example above, note-date can work as the field to use in your task query (because it’s in the right format, it’s the date you wanted and it’s independent from the creation date).

With this type of metadata you can create a DQL query similar to this:

WHERE !completed
WHERE note-date AND note-date < date(today)
SORT note-date DESC

This is an example. But there are other ways.
I insist: you need to know something about the tool to know what and how structure your metadata. (mainly the “logic”, not the code knowledge)

Thanks, but wouldn’t that mean I do have the yaml frontmatter on all daily notes? I presume that was one of the reasons I started digging into js.

Yes, in all your daily notes (you can use a template…). But the reason is: you don’t want to change your daily note title format. And it’s indifferent if dql or dvjs… the issue is the same (js can’t do any miracle here: metadata is equal to dql or js queries).
It’s possible to create a more complex query to transform, for example, “Mar” in “03”, but I’m not sure if it’s not worth.
You can also use a template to auto-create an aliases field to use as an alternative title… etc, etc. But as you can see the issue is in your prerequisites. If no direct solution to solve it you need to find an alternative way (and check if it’s worth it).

Just an extra: if you want to check all metadata in your specific note, use this query in that note (it’s an inline query):


or an inline js query with a more structured output:


Thanks, let me play a bit further, I’ll be back :slight_smile: But thanks a lot for your time and input!

1 Like

I had a problem similar to yours - the format yyyy-mm-dd is not one that immediately makes sense to me. I much prefer the “plain language” variation that I was used to with the DNP in Roam.

But, after a while, I realized I was just making life difficult for myself by using a filename format different from what Dataview uses – so I conceded the point. My compromise was to include this code in my DNP template as a Header 2 second line.

{{date:dddd, MMMM Do, yyyy}}

It resolves to a date in a format like this:

Thursday, March 3rd, 2022

When looking at a DNP I ignore the filename and look at the second line. Dataview is happy and I don’t have to devote brain cycles to interpreting what 2022-03-03 means.

The big advantage is that I can now use the simplified Dataview task query syntax.

1 Like

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