Hello,
The problem is that journal pages names are not real dates, yet they have the property :block/journal-day
which is a date we can use.
Here is how we can do what you’re looking for :
{
:title "Tasks completed before today"
:inputs [:today] ; inject the current date
:query [
:find (pull ?b [*])
:in $ ?that-day ; name the variables injected with :inputs
:where
[?b :block/properties ?properties]
[(get ?properties :completed) ?completed-at]
[?b :block/ref-pages ?p] ; find the page references
[?p :block/journal? true] ; which are journal pages
[?p :block/journal-day ?d] ; extract their date
[(< ?d ?that-day)] ; which should be older than the date passed with :inputs
]
}
:today
needs to be injected because it is a dynamic variable (changing every day) so you need to add the lines :inputs [:today]
and :in $ ?that-day
(?that-day
is the name of the variable holding the value of :today
)
Then like you were doing, look at the blocks that have a :completed
property and then find all the pages that those blocks are referencing. Look at the :block/journal-day
of those pages and compare them with the date you injected through :inputs
.
Note that this solution is not really good because if you reference another (past) journal page in your block it will be in the results.
(I tried without success to parse the value of ?completed-at
to use that value instead of the :block/ref-pages
)
Hope it helps