Sort deadline query chronologically


I use the advanced query for the next 7 days deadline.
I’d like to sort the answer chronologically by deadline (not registration date).
Is there a syntax for that ?

Thanks very much !


I use the following. I don’t claim to be an expert on the query language, which I do not find intuitive, but it seems to sort by date (note the sort-by statement)

However, it would be absolutely great if standard queries were able to sort by deadline / schedule (rather than date created). It would put Logseq far ahead of other apps (Obsidian, Roam, RemNote). Currently none of them can do this.

It would also be great if Org-style scheduled tasks, and dates represented as page references were treated in exactly the same way.

{:title [:h1 "📆 near TODOs (next 7 days, scheduled or deadline)"] 
     :query [:find (pull ?block [*])
          :in $ ?start ?next
            [?block :block/scheduled ?d]
            [?block :block/deadline ?d])
          [(>= ?d ?start)]
          [(<= ?d ?next)]]
        :result-transform (fn [result]
                            (sort-by (fn [d]
                                       (get d :block/scheduled) (get d :block/scheduled) ) result))
  :inputs [:today :7d-after]
  :collapsed? false}


Thanks Hulk (and agree with you, this possibility should be a great strength for logseq over the other apps).

On my side what you propose doesn’t sort by deadlines/schzdule date.

1 Like