Query & sort for pages with date:: property

Hi,
I searched the forums and asked this already in the Discord, but maybe somebody here can help.

I would like to get a list of events, sorted by date (ideally, excluding past events).

  • All events are individual pages within the namespace “event”, page name: "event/my first event ".
  • The date is set in the page property date, e.g. date:: [[Nov 4th, 2023]]

Any help appeciated!
Thanks!

Here’s an attempt based on your provided info

query-properties:: [:date :page]
#+BEGIN_QUERY
{:title [:b "Upcoming events"]
 :query [:find ?d (pull ?p [*])
  :keys d block
  :in $ ?today
  :where
   [?ns :block/name "event"]
   [?p :block/namespace ?ns]
   [?b :block/page ?p]
   [?p :block/properties ?prop]
   [(get ?prop :date) ?date]
   [?j :block/journal-day ?d]
   [(> ?d ?today)]
   [?j :block/original-name ?name]
   [(contains? ?date ?name)]
 ]
 :result-transform (fn [res] 
  (sort-by (fn [s] (get-in s [:block/properties :d])) < (map (fn [m] 
     (update (:block m) :block/properties 
         (fn [u] (assoc u :d (get-in m [:d]))
         ))
  ) res))
 )
 :inputs [:today]
}
#+END_QUERY

Amazing! Thanks a lot! This does exactly what i need!

1 Like