On This Day - Query

I love the feature in Day One the journal app - On This Day. It gives me a view of all the previous journal entries for that day in the year.

I suspect it could be possible to make a query to do the same in Logseq. I would need to have the results showing the same as if the page was embedded.

Wondered about adding a tag which gives the month and day and have the query search for that. Maybe I could automate adding the tag to every journal entry. The tag could be 05-24

Or perhaps do a query which just searches for May 25th.

I’d love an “On This Day” query. I found this in the forum:

By @WsinLogseq

But it gives me an error that I have a broken config.edn when I put it in there. @WsinLogseq do you have any suggestions?

And ideally, I’d like “On This Day” a year ago, two years ago, etc – basically anything on the same day/date.

1 Like

I have this one here in my default-queries, but I do not know anymore from where I copied it.

{:title "⌛ On this day..."
    :query [:find (pull ?b [*])
       :in $ ?today
       :where
       [?b :block/page ?p]
       [?p :page/journal? true]
       [?p :page/journal-day ?jd]     
       [(str ?jd) ?jds]     
       [(subs ?jds 4 8) ?md1]
       [(str ?today) ?td]
       [(subs ?td 4 8) ?md2]
       [(= ?md1 ?md2)]
       [(< ?jd ?today)]
	]
	:inputs [:today]
    :breadcrumb-show? true
    :collapsed? true}

Maybe it is important to say that my daily journals have the format YYYY/MM/DD e.g. 2023/01/13 because there is a calculation done where they compare the page names (today, with other journal pages) without the year.

3 Likes

Thank you for sharing!

Yeah, I use the “standard” naming of MON XXth, YYYY so would need to modify. That’s a great idea of just comparing MONTH + DAY. Should work!

1 Like
{:title "⌛ ON THIS DAY"
    :query [:find (pull ?b [*])
            :in $ ?today
            :where
            [?b :block/page ?p]
            [?p :block/journal? true]
            [?p :block/journal-day ?jd]
            [(- ?today ?jd) ?days]
            [(mod ?days 10000) ?r]
            [(= 0 ?r)]
            [(> ?days 0)]]
    :inputs [:today]
    :collapsed? false}

I have been using this version. Now when I have several years’ worth of journal entries, I’d like to have results displayed as folded by the heading (ie. date). Can anyone help me to get that done?

if you add :group-by-page? true works?
You can add after the

:inputs [:today]

The :group-by-page? true has no effect on the output. If I set :collapsed? to true it only collapses the top-level, ie. “ON THIS DAY” block.

1 Like

It is strange, it does work for me. collapsed and group-by-page should not have conflict since acting on different things.

To clarify, I’d like to have the daily entries returned by the query folded, not the whole “On This Day” block. Now they all render unfolded, which takes lot of space especially if multiple year entries are found. Screenshot:

i do not know how to collapse them per date automatically. I would like to have this too.
@Siferiax do you know how to do it?
Thanks

@Federico_Frosini @jkiviluoto
No idea how to accomplish that!
The collapsed state you can manually do is actually controlled by changing the css class used in the result css.

Not collapsed, result is in div class initial:

Collapsed, result is in div class hidden:

not sure I am able to do something that complex :smiley:

Queries are the single biggest limitation of logseq - regular users do not stand a chance of writing an advanced query themselves - therefore either copy&pasting a query from the internet works or it doesn’t.

The query below is working for me, so that is a start, but here is what I am missing: I capture other data in pages, and then add the date to that page’s name or property block or any random block within the page.

I would like to see all of those pages show up as well, not just journal entries, as that is all stuff I worked on on that day.

Query that works for me:

    {:title "⌛ ON THIS DAY"
    :query [:find (pull ?b [*])
            :in $ ?today
            :where
            [?b :block/page ?p]
            [?p :block/journal? true]
            [?p :block/journal-day ?jd]
            [(- ?today ?jd) ?days]
            [(mod ?days 10000) ?r]
            [(= 0 ?r)]
            [(> ?days 0)]]
    :inputs [:today]
    :collapsed? false}

It is possible to search for dates everywhere, but such a query would gradually become very slow. The correct approach is to link those dates back to the respective journal entry, then find them all in that place and therefore through your current query.

1 Like