On This Day Query Page

Over the past 7 years or so I have used journey as my go-to journal app. Easy to use, on the phone and the computer, can upload images, etc. but then in 2020 (for me a least), PKM apps burst onto the scene.

I soon found myself exclusively using Logseq as my journalling app. The ease of being able to write in it (I mostly use my laptop as opposed to my phone), there is no lock-in format and my journals forming part of my notes were all too good to pass on.

However, I found that one thing I missed was the "On This Day" / "Today" pop-up that allowed me to see historical journal entries made on this day 1, 2, 3 etc. years ago. I think this is a feature any journalling app should have by default as it allows you to see what was happening in the past and the journey you are on.

After some digging around, I have found a way of being able to reproduce the "On This Day" feature in Logseq. I am even happier to say that all it takes is a query, a few clicks here and there and you are good to go.

First off, let's create a page called "On This Day" - or a name of your choice.

The Query

The query that is needed to recall pages made on this day in the past years is a bit complex, and I will not pretend to understand it. All I can say is thank you to cc1 for creating this and posting it online.

#+BEGIN_QUERY
{: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? false}    
 #+END_QUERY

You can tweak a few of the settings to your liking and preference. For example, having :collapsed? True will result in the query being collapsed by default.

UPDATE: Bas / Tools on Tech commented on the query and what each step means. Check it out at the end of the article. Basically, it gets the journal day and turns it into a string that's YYYYMMDD and then removes the first 4 characters to get MMDD to compare with MMDD of today.

With the above query, you can now retrieve your notes from the previous years and should see something like the screenshot below.

Or with a bit of spice and a custom theme / plugin.

Whilst Logseq (and other apps) are great for linking to different pages and retrieving information, how often do you really go back and look at your full journal pages?

The beauty of this query is that you can discover things you may not have otherwise, like why last year was quite an eventful day.

The Few Clicks Here and There

With the On This Day (or whatever you called it) page set up, we can now navigate to it and right-click the title.

Click "Add to Favourites" to see a new link under your favourites on the left-hand side. Drag and drop the link into your preferred position, I like mine on the top of my favourites so that I see it first.

You should see something along the lines of the following:

All you now need to do, is each day, click the first link and either laugh or be worried about what was going on in your life in the past.

Other Tweaks

The query as currently set up sits outside the journals page and always defaults to today's page as opposed to the journal page (for example if I put the query on 25 January 2023 - I will still get back today's results). I do not see this as a shortcoming but more of a bonus.

When writing and taking notes, I do not want to be distracted by what I was doing last year (yes I could collapse the query, but less is more. Also, I do not want to be overwhelmed by too much information about all of my historical journals on every journal page I navigate to.

In essence, whilst tweaks are possible, I will be starting easy. I just want to see what I did in the past on this day. If I missed yesterday's, then tough luck for me.

A quick video of how to get this set up has been included below:

Breakdown of the Query

Thank you to Bas / Tools on Tech for adding commentary to the query and how it works. Much appreciated.

#+BEGIN_QUERY
{
 ; Set Title
 :title "⌛ On this day..."
 ; Get all blocks
    :query [:find (pull ?b [*])
       ; We want to filter on Today, so we get that variable as input (See input)
       :in $ ?today
       :where
       ; Now to filter, first, we only want journal pages
       [?b :block/page ?p]
       [?p :page/journal? true]
       ; Then we fetch the Day of the Journal page, store it in ?jd
       [?p :page/journal-day ?jd]     
       ; Tricky part, but what happens it turns date into string
       ; Not sure, but I assume unix timeformat so YYYYMMDD
       ; Then use subs to cutoff the YYYY 
       [(str ?jd) ?jds]     
       [(subs ?jds 4 8) ?md1]
       ; Then we do the same trick for today
       [(str ?today) ?td]
       [(subs ?td 4 8) ?md2]
       ; What we are left with is a compare of Today without year, matches pages
       ; without year 
       [(= ?md1 ?md2)]
       ; Finally filter out today, as that's not history....yet
       [(< ?jd ?today)]
    ]
    ; Make Logseq provide todays date
    :inputs [:today]
    ; Why yes we want to see the year
    :breadcrumb-show? true
    ; And show me everything unfolded
    :collapsed? False
}
 #+END_QUERY

Hope you find this useful and thanks for reading / watching.

Last updated