Query a block from a journal page X days ago relative to the journal page where the query resides

Hi!
I’m trying to add two queries into my template for the daily journal page. I’d like to review my journal notes form the past.

The motivation behind this is that it’s one thing to write your journal, but another one to actually review it and read your entries.

Say I am on a journal page 2022-11-29, I’d like to query for a block(s) tagged with #[[Today’s Entry]] from the journal page a year ago 2021-11-29 and a week ago.

Currently I have these two simple queries:
:arrow_backward: Last week
{{query (and (between -1w -1w) [[Today’s Entry]] )}}

:rewind: Last year
{{query (and (between -1y -1y) [[Today’s Entry]] )}}

This does almost what I need it to. The only problem is that the date is relative to today and I’d like to have it relative to the date of the journal page that the query is on.

I’d be really grateful if someone here could give me a steer on how to solve this or even adjust my simple queries to change the behaviour.


What I’ve found in trying to solve this on my own:

Hello,

If I understand this correctly, I think that the queries defined from the config :default-queries are only played on the journal page of today.

Ah! Interesting I didn’t know that these things exist. Presumably this is what powers for example this built in “Next” section?

Unfortunately this does not answer my question of how to make the (between ) filter, use the time relatively to the journal page rather than the current date. Maybe there’s some alternative way of doing it without the between filter? :thinking:

Ah! Interesting I didn’t know that these things exist. Presumably this is what powers for example this built in “Next” section?

Yes it is.

Unfortunately this does not answer my question of how to make the (between ) filter, use the time relatively to the journal page rather than the current date. Maybe there’s some alternative way of doing it without the between filter? :thinking:

You can get the current page with a dynamic variable like this : {{query <% curent page %>})
Then you will need, I think, to get the :block/journal-day of this current page… but after that I don’t know how to compute “a week before” the date you have.
The dynamic variables seems to all be relatives to the current date…

That’s interesting. Given that :7d or :7d-before are relative to the current date, these won’t help with the task. To make it work, we would need a way to calculate date-time values on the fly. A quick search lead me to core.clj-time, which has to be imported as a dependency.

Is this this dependency available by default? Similarly to how clojure.string is available as str.

Generally, which dependencies are available? A lot of tutorials rely on java or javascript modules. Is any of that available for queries? I played around in the cosole a while back and was able to call some of the functions defined for, if I’m not mistaken, the API to retrieve blocks by UUID, for instance.

Anyway, without a means to perform date value calculations, I don’t see how “the last week” could be dynamically queried.