@holroy, thank you so much. I’m relatively new to Obsidian, and over the past few months, I’ve been working on tailoring my vault alongside my job. The possibilities with Obsidian and its amazing community plugins are truly endless, but I wouldn’t have been able to achieve my goal without the support of community members like you.
Your recommendations have made the code much simpler and more readable:
- Avoiding duplicate conditions
- Skipping unnecessary date-to-date conversions
- Using the file’s date property
I’ve tried using just Dataview, but as you mentioned, the results don’t compare to the Tasks plugin’s short mode, especially with its helpful features like editing and postponing tasks.
While my vault is small and manageable, I can see how querying a larger vault with thousands of notes could become slow and resource-intensive. I plan to refine the code further during my free time, trying to consolidate it into one query or, at the least, optimize it to use fewer queries.
Just one adjustment to your code:
Date comparisons in dataview queries don’t work correctly when using something like:
( scheduled and scheduled < ${ thisDate } )
I had to explicitly convert it to a date for it to work properly. Here is the final code (just reviewd parts) :
const thisDate = dv.current().file.day.toFormat("yyyy-MM-dd")
// --- OVERDUE ---
const dv_qry_overdue = `
TASK
FROM #task1
WHERE !completed and (
( scheduled and scheduled < date( ${ thisDate } ) ) or
( due and due < date( ${ thisDate } ) )
)
`
const tasks_qry_overdue = `\
> ( scheduled before ${ thisDate } ) OR ( due before ${ thisDate } )
> not done
> short mode
> hide tags
> hide task count
> group by filename
> sort by priority`
// --- TO-DO ---
const dv_qry_todo = `
TASK
FROM #task1
WHERE !completed and (
( scheduled and scheduled = date( ${ thisDate } ) ) or
( due and due = date( ${ thisDate } ) )
)
`
const tasks_qry_todo = `\
> ( scheduled on ${ thisDate } ) OR ( due on ${ thisDate } )
> not done
> short mode
> hide tags
> hide task count
> group by filename
> sort by priority`
// --- DONE ---
const dv_qry_done = `
TASK
FROM #task1
WHERE completed and
( completion and completion = date( ${ thisDate } ) )
`
const tasks_qry_done = `\
> ( done on ${ thisDate } )
> short mode
> hide tags
> hide task count
> group by filename
> sort by priority`