How to write query to show blocks with date as today

Before coming to logseq I was using workflowy, I had developed pattern of task management where I search for ‘today’ to see what is pannned for today , tomorrow for tomorrow.

Replicating same in logseq, I tried to write queries to show block having date as today, unsuccessful. Could anyone help me in writing query to select blocks which has date as today mentioned anywhere in block.content?

I am new to closure / datalog, started to us logseq couple of days before.

1 Like

You should use either a reference to a journal day or the scheduled command.
Then check out this topic:

Otherwise you can give the version 0.9 query builder a try as well.

somehow I was able to build one with having static date in the query, building on top of what given by query builder.

#+BEGIN_QUERY
{
:title [:b "Show blocks with given date"]
:query [:find (pull ?block [*])
:where
[?block :block/content ?blockcontent]
[?block :block/page ?page]
[?page :block/name ?pagename]
( or
[(clojure.string/includes? ?blockcontent "Apr 7")]
[(clojure.string/includes? ?blockcontent "04-07")]
)
]
}
#+END_QUERY

Can someone help in making this dynamic? Like if I visit journal page - of today I see the tasks in that query.

I’m still not quite sure what your content looks like?
Here’s an example:

I have a task which references a journal page (the current one, for the example).
Then on that journal page I have a query that gets all tasks that reference that same journal page.
If your data is different from this, then please specify.

Query:

#+BEGIN_QUERY
{:title [:b "Show blocks with given date"]
 :query [:find (pull ?block [*])
   :in $ ?current
   :where
     [?journal :block/name ?current]
     [?block :block/refs ?journal]
     [?block :block/marker ?mark]
     [(contains? #{"TODO" "DOING" "LATER" "NOW"} ?mark)]
 ]
 :inputs [:current-page]
}
#+END_QUERY

@Siferiax Thank you for all of your query expertise on the forums.

How would I modify your query about to show tasks tagged to any journal page?

I changed the order of statements for performance reasons.

#+BEGIN_QUERY
{:title [:b "Show tasks tagged with journal pages"]
 :query [:find (pull ?block [*])
   :where
     [?block :block/marker ?mark]
     [(contains? #{"TODO" "DOING" "LATER" "NOW"} ?mark)]
     [?block :block/refs ?journal]
     [?journal :block/journal? true]
 ]
}
#+END_QUERY
1 Like