Weekly query: Get pages for the week on which the query is written

Hi Everyone.
I have a template for a query for my weekly journal (that track my time spent on projects). At the moment I have the start and end date of the week hard coded in the :inputs field.
E.g. for my journal page 2025-W2 I have the following query:

#+BEGIN_QUERY
{
:query [
  :find (pull ?project [*]) (sum ?duration)
  :with ?b
:keys project duration
:in $ ?start ?end
  :where
  [?b :block/page ?p]
  [?b :block/refs ?r]
  [?r :block/name "timetracker"]
  [?p :block/journal? true]
  [?p :block/journal-day ?d]
 [?b :block/properties ?props]
[(get ?props :project) ?project-val]
[(get ?props :duration) ?sdur]
[(* 1 ?sdur) ?duration]
[?project :block/original-name ?project-name]
[(contains? ?project-val ?project-name)]
(between ?b ?start ?end )
]
:inputs [ 20250106 20250110 ]
:result-transform (fn [result] (map (fn [r] (update (:project r) :block/properties (fn [p]
(assoc p :days(/ (:duration r) 8) :hours (:duration r) :project (:block/original-name (:project r)))
))
) result )
)
}
#+END_QUERY

where I entered manually the date of Monday and Friday in the inputs.

Do you know how I could use automatically the date of the journal page on which the query is written? Note: In my case it does not need to be from Monday to Friday and this could also include the saturday / sunday if this would be easier.

Thank you for your support and kind regards

  • To get the (assuming journal) page on which the query is written:
    • Get its (lowercase) name by using :inputs [ :query-page ]
    • Pass it as a variable by using e.g. :in $ ?journal-name
    • Get the page (ID) from the name by using e.g. [?j :block/name ?journal-name]
  • To compare against the week of the found journal:
    • Get the date (YYYYMMDD) of the journal by using e.g. [?j :block/journal-day ?j-d]
    • Calculate the ?weekBegin and ?weekEnd of the week of ?j-d similarly to this post (which is for next week, i.e. easier).
      • Yeah, this step is overly complicated, it will take much effort.
    • The comparison will look like this:
      [(>= ?d ?weekBegin)]
      [(<= ?d ?weekEnd)]