Blocks with (todo or scheduled or deadline) between two dates

I want to combine three requests into one query. Not sure what to do. So the requests are

  1. Search TODO with (scheduled or deadline) dates where Dates are between A and B.
  2. Search TODO with no (scheduled or deadline) dates but are in Journal Pages between A and B dates.
  3. Search SCHEDULED (w/ or w/o TODO) and the dates are b/w A and B
  4. Same as #4 but refer DEADLINE.

Here is what I did but did not generate result.

{:title ":bubble_tea::bubble_tea::bubble_tea::bubble_tea: "
:query [:find (pull ?block [*])
:in $ ?start ?next
:where
(or
[?block :block/scheduled ?d]
[?block :block/deadline ?d]
[?block :block/content ?text]
[(clojure.string/includes? ?text “TODO”)]
)
[(>= ?d ?start)]
[(<= ?d ?next)]]
:inputs [:7d-before :today]
:result-transform (fn [result]
(sort-by (fn [b]
(get b :block/scheduled)) result))
:group-by-page? false
:collapsed? false}


I also tried

{:title “:muscle:
:query [:find (pull ?h [*])
:in $ ?start ?next
:where
[?h :block/marker ?m]
[(contains? #{“LATER” “TODO” “SCHEDULED” “DEADLINE”} ?m)]
(or-join [?h ?d]
(and
[?h :block/ref-pages ?p]
[?p :block/journal? true]
[?p :block/journal-day ?d])
[?h :block/scheduled ?d]
[?h :block/deadline ?d])
[(> ?d ?start)]
[(< ?d ?next)]]
:inputs [:3d-before :7d-after]
:collapsed? false}


Have you managed easier separate queries for each one of your requests?

  • If no, begin with those.
  • If yes, share them here.

I did.
Searching for scheduled and deadline between two days. This one is simple.

{:title “:bubble_tea::bubble_tea::bubble_tea::bubble_tea:
:query [:find (pull ?block [*])
:in $ ?start ?next
:where
(or
[?block :block/scheduled ?d]
[?block :block/deadline ?d]
)
[(>= ?d ?start)]
[(<= ?d ?next)]]
:inputs [:7d-before :today]
:result-transform (fn [result]
(sort-by (fn [b]
(get b :block/scheduled)) result))
:group-by-page? false
:collapsed? false}


and searching for TODOS that are made in Journals between 2 days.

{:title ":date: "
:query [:find (pull ?h [*])
:in $ ?start ?next
:where
[?h :block/marker ?marker]
[(contains? #{“NOW” “LATER” “TODO”} ?marker)]
[?h :block/page ?p]
[?p :block/journal? true]
[?p :block/journal-day ?d]
[(> ?d ?start)]
[(< ?d ?next)]]
:inputs [:today :7d-after]
:group-by-page? false
:collapsed? false}

Something like this:

#+BEGIN_QUERY
{
 :inputs [:-3d :+7d]
 :query [:find (pull ?b [*])
 :in $ ?start ?end
 :where
   (or-join [?b ?d]
     (or
       [?b :block/scheduled ?d]
       [?b :block/deadline ?d]
     )
     (and
       [?b :block/marker ?marker]
       [(contains? #{"NOW" "LATER" "TODO"} ?marker)]
       [?b :block/page ?p]
       [?p :block/journal-day ?d]
     )
   )
   [(> ?d ?start)]
   [(< ?d ?end)]
 ]
}
#+END_QUERY
2 Likes

It worked. Thank you!

I find it more useful to set group by page to true.