Birthday query for a property

Below I finally managed to finish a Birthday query. Maybe someone will find it useful. I have it in my default-queries and it shows a birthday if the property “birthday:: [[2000/01/31]]” is filled with today’s day.

If someone can make it easier, shorter, more readable please let me know :slight_smile:

{:title "🎂 Birthday"
  :query [:find (pull ?b [*])
    :in $ ?today
    :where
       [?b :block/properties-text-values ?props]
       [(get ?props :birthday) ?birthday]
       
       [(str ?birthday) ?birthdayString]
       [(subs ?birthdayString 7 9) ?month]
       [(subs ?birthdayString 10 12) ?day]

       [(str ?today) ?td]
       [(subs ?td 4 6) ?todayMonth]
       [(subs ?td 6 8) ?todayDay]

       [(= ?month ?todayMonth)]
       [(= ?day ?todayDay)]
       
]
:inputs [:today]
:collapsed? false}

Well done! I would say this works just fine, unless you want to get into regex I suppose.

1 Like

Another birthday query that works for any date format: Discord

It does not work for me.
It might be linked to the date format?
I have MMM do, yyyy.

or the property?
I use markdown made birthday::

any ideas how to use?

The discord example is using the birthday value as a journal link.
So when you use a link to your journal page as the birthday value.

So for example your journal page is
May 14th, 2023
Then your birthday property would be [[May 14th, 2023]] (that is, reference to that journal page)

Thanks. I did like this but it is not working for me. I don’t understand why for the today the string subs operation uses different number compared with the burthday string. Is it normal?

The :today input is always as yyyymmdd regardless of your date format setting for the journal.
So to break it apart we need specific subs.
The original user posted they used a link to their journal as the property which has a format of yyyy/mm/dd thus would need different subs to extract.
If your journal refs are as previously stated, then the query from the original post will not work for you.
The query that Darwis linked to, would work regardless of your journal date format settings.

Thanks clear.
How to change the query considering that my birthday are in the format May 14th, 2023?

I used the Darwis one but I get a table and I want to get block with the page (person) referenced (like group-by-page).

Does it make sense?

Makes sense. I changed the OP query to combine it with the date format not mattering.
Let me know if this helps.

#+BEGIN_QUERY
{:title "🎂 Birthday"
  :query [:find (pull ?b [*])
    :in $ ?today
    :where
      [?b :block/properties ?prop]
      [(get ?prop :birthday) ?birth]
      [?j :block/journal-day ?birthint]
      [?j :block/original-name ?jname]
      [(contains? ?birth ?jname)]
      [(str ?birthint) ?birthstr]
      [(subs ?birthstr 4) ?birthmd]
      [(str ?today) ?td]
      [(subs ?td 4) ?todaymd]
      [(= ?birthmd ?todaymd)]
      [?b :block/page ?p]
]
:inputs [:today]
:collapsed? false}
#+END_QUERY
1 Like

Thanks it is perfect!!!

1 Like

If I need the birthday date to be within three days or less from today, what should I do? I have tried several methods, but none of them have been successful.
such as [(<= (- ?todaymd ?birthmd) 4)]

That’s not correct datalog syntax :slight_smile: we need to change the input and a bit of the query.

I’m assuming you mean after today.

#+BEGIN_QUERY
{:title "🎂 Birthday"
  :query [:find (pull ?b [*])
    :in $ ?today ?day
    :where
      [?b :block/properties ?prop]
      [(get ?prop :birthday) ?birth]
      [?j :block/journal-day ?birthint]
      [?j :block/original-name ?jname]
      [(contains? ?birth ?jname)]
      [(str ?birthint) ?birthstr]
      [(subs ?birthstr 4) ?birthmd]
      [(str ?today) ?td]
      [(subs ?td 4) ?todaymd]
      [(str ?day) ?strday]
      [(subs ?strday 4) ?daymd]
      [(<= ?todaymd ?birthmd ?daymd)]
      [?b :block/page ?p]
]
:inputs [:today :+3d]
:collapsed? false}
#+END_QUERY

The Datalog script is working perfectly. I’m extremely grateful for your assistance!

1 Like