Dataview of uncompleted tasks scheduled in the past

What I’m trying to do

Create a daily page that lists 1) tasks due today, 2) tasks scheduled today, 3) uncompleted tasks due in the past and 4) uncompleted tasks scheduled in the past.

I’ve successful done 1, 2 and 3 but 4 is providing tasks with 1) no date in the schedule and 2) tasks scheduled in the future.

Things I have tried

Here’s my code. Note that I’m using date format YYYY-MM-DD in my tasks.

TASK
FROM !"X PKM"
WHERE !completed
WHERE scheduled < date(this.file.cday)
WHERE contains(tags, "#todo") OR contains(tags, "#nextaction")

I have also tried changing ‘scheduled’ for :date: but get the same result:

dataview
TASK
FROM !"X PKM"
WHERE !completed
WHERE 📅 < date(this.file.cday)
WHERE contains(tags, "#todo") OR contains(tags, "#nextaction")

I have played with adding in WHERE !scheduled = null but that gave no results.

Here’s a screenshot of an erroneous result where this.file.cday = 2023-06-04

You’re using this.file.cday which is the actual creation date of your file. To get the date referred to in the name of your file (or possibly in the date field), you need to use this.file.day.

And you shouldn’t need to do date( ... ), since it’s already a date.

Thanks holroy, I appreciate you taking the time to respond. I’ve tried the following ;

dataview
TASK
FROM !"X PKM"
WHERE !completed
WHERE scheduled < this.file.day
WHERE contains(tags, "#todo") OR contains(tags, "#nextaction")
SORT priority desc

The dataview result still shows innacurate results. It seems to show any task with the ‘< this.file.day’ in it, reglardless of whether it is the 'scheduled date or not.

For example, this screenshot shows the same inaccurate task as I mentioned above. I have toyed with add 'WHERE includes the scheduled emoji but that still risks returning results that have a date in the past where it is scheduled in the future.

Using the plus emoji ( :heavy_plus_sign: ) indicates when the task is created, not when it’s scheduled… The scheduled emoji is the hour glass ( :hourglass_flowing_sand: ).

Lets try to illustrate what’s happening in your query (besides the created vs scheduled emoji issue), so paste the following into a file of its own:

---
Tags: f61031
date: 2023-06-07
---
questionUrl:: http://forum.obsidian.md/t//61031

- [ ] No scheduled ➕ 2023-06-05
- [ ] Yesterday⏳ 2023-06-06
- [ ] Today⏳ 2023-06-07 
- [ ] Tomorrow ⏳ 2023-06-08
- [x] Answer request ➕2023-06-09


```dataview
TABLE WITHOUT ID task.text, task.created, task.scheduled, task.scheduled < this.file.day
FLATTEN file.tasks as task
WHERE !completed
WHERE file = this.file
```

Here we define some tasks, and then build up a TABLE query to display these tasks and details related to these tasks. This can be a very useful strategy when debugging (aka looking for errors) in our queries. The query displays the following:

Here we can see the emoji issue I mentioned, and the scheduled date, and more interesting in the last column we can see how dataview interprets the scheduled < this.file.day statement. Notice how the first row is true, since it’s considering the empty value of scheduled to be less than a date.

This is another way of indicating that no date isn’t as vital as given date, or that we’ll respect your scheduled date if you’ve set it, and if not we’ll assume it’s a normal task you want to see and execute at any given point in time.

To counter for this, and eliminate all tasks not having set a scheduled date, you can add the scheduled another time just to verify it has a value. So in my context (aka you could add this to the note above) the query would then become:

```dataview
TASK
WHERE !completed
WHERE scheduled AND scheduled <= this.file.day
WHERE file = this.file
```

And we’ll get the output of:
image

So adapt your query by adding scheduled AND in front of the date comparison, if and only if you require the scheduled date to be set.


Trivia question; Which of these are true (if any)?

now < today? `= date(now) < date(today) `
now = today? `= date(now) = date(today) `
now > today? `= date(now) > date(today) `
Spoiler: Open to see answer

date(now) contains the time as well as the date, so it’s larger than date(today) which only contains the date. This can be a vital difference if doing date comparison in a daily note and so on…

date(now): `= dateformat(date(now), "yyyy-MM-dd HH:mm:ss")`
date(today): `= dateformat(date(today), "yyyy-MM-dd HH:mm:ss")`
1 Like

Hi Holroy,

Thanks again for your time and particularly for such a comprehensive response. You’ve shown me how dataview treats unscheduled tasks. I had played with scheduled = null to no effect, but I can see that including ‘scheduled’ is akin to using ‘due’.

For those that are interested, this is my modified dataview query, which works as I intended:

dataview
TASK
FROM !"X PKM"
WHERE !completed
WHERE scheduled AND scheduled < this.file.day
WHERE contains(tags, "#todo") OR contains(tags, "#nextaction")
SORT priority desc

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