How to use maximum date as input?

Hi
I have a block which contains the result of a query - a date. But this block displays the date as a number.
Now I want to create a query that uses that block (it’s the parent block) as an input, and compares the block’s date against another date. But the date is a number…
How can I convert that number to a date for the query?

Thanks!

Could you provide specific examples of those numbers, dates, and maybe the query under construction itself?

Sure
So I started setting a property ‘futuremeeting’ with value as a name of a person
I have a template for a 1v1 meeting with that person
Inside the template I run a query getting all the blocks which has that property and that person’s name.
The problem is, I’m getting all the blocks, even the old ones, i.e. even the ones older than the last meeting with him.
So I’m trying to run a query that will get all the blocks with the property, where the block’s date is newer than the date in which the last 1v1 meeting took place.

I couldn’t find a way to do that in 1 query, so I divided it:

  1. Running a query that gets the date of the last 1v1 meeting
  2. as a child block, and using the parent block (with the first query’s result as input), trying to get all the relevant blocks which are newer than the last 1v1 meeting date (= the first query’s result)

Here’s the first query:

#+BEGIN_QUERY
{
 :title [:b "🧨 max meeting day"]
 :query [
         :find (max ?meetingday)
         :where
         [?b :block/page ?p]
         [?p :block/journal? true]
         [?b :block/content ?content]
         [(clojure.string/includes? ?content "[[Stas]] #1v1")]
         [?p :block/journal-day ?meetingday]
         ]
 :breadcrumb-show? true
}
#+END_QUERY

The result is: 20240528

Now I want to use it as an input and convert that number to a date, so that I would be able to run this query:

#+BEGIN_QUERY
{
 :title [:b "🧨 sub query"]
 :query [
         :find (pull ?c [*])
         :in $ ?lastdateblock
         :where
         [?c :block/page ?pc]
         [?pc :block/journal? true]
         [?pc :block/journal-day ?cday]
         (property ?c :futuremeeting "Stas")
         [(> ?cday  ?lastdateblock)]
         ]
 :breadcrumb-show? true
 :inputs [:parent-block]
}
#+END_QUERY

But the results returned contains blocks with that property and value, which are older than that date (May 28th 2024)

:parent-block doesn’t return a date. This can be confirmed with a query like this one:

#+BEGIN_QUERY
{:query [:find ?lastdateblock
   :in $ ?lastdateblock
 ]
 :inputs [:parent-block]
}
#+END_QUERY

It is not possible to divide queries like that. To combine the queries, try something like this:

#+BEGIN_QUERY
{
 :query [:find (pull ?c [*])
   :where
     [?p :block/journal-day ?maxmeetingday]
     [?b :block/page ?p]
     [?b :block/content ?content]
     [(clojure.string/includes? ?content "[[Stas]] #1v1")]
     (not-join [?maxmeetingday]
       [?p :block/journal-day ?meetingday]
       [(> ?meetingday ?maxmeetingday)]
       [?b :block/page ?p]
       [?b :block/content ?content]
       [(clojure.string/includes? ?content "[[Stas]] #1v1")]
     )
     [?pc :block/journal-day ?cday]
     [?c :block/page ?pc]
     (property ?c :futuremeeting "Stas")
     [(> ?cday ?maxmeetingday)]
 ]
 :breadcrumb-show? true
}
#+END_QUERY
2 Likes

Wow. Amazing, thank you!!
I spent so much time trying to get this to work.
Do you have a guide / doc reference for advanced queries? All the searches I made and I’ve never seen the ‘join’ parts

Thanks again!

Make sure to read the reference. For the rest look in the forums.

1 Like