How to create a property similar to a variable: date /week

Hi, I’m creating properties for my template.

I want to insert the date automatically, but I’m not sure about the syntax. Is there any way I can find the documentation for it?

date:: <% today % >

I try this way but won’t work.

Welcome. Try this query:

#+BEGIN_QUERY
{:query [:find ?today :in $ ?today]
:inputs [:today]
}
#+END_QUERY

I assume you want that date to stay fixed? I had the same requirement as I am doing a lot of Block-Templates with Custom Commands and wanted to pre-populate the Custom Command when invoked so I have less friction at inputting the actual data.

If that is the case, and you are working in the journal page, then define a Macro (Macros, Queries and Templates have access to dynamic variables) in the macros section of your config.edn:

:macros {
 "today-fixed" "<% current page %>"
}

and call it with:

date::  {{{today-fixed}}}

If you want a property that is updated to “today’s date” any time you refresh the block, then:

:macros {
 "today" "<% today %>"
}

Hope it helps.

1 Like

EDIT: (misunderstanding)

How would you write that in a property value? Or how can you call it inside a property value as a variable? :face_with_diagonal_mouth:

No, I literally have it like I wrote.
But I tried your way and works too … :-/

I can’t find much info about macros so I looked at the example in config.edn: ;; {"poem" "Rose is $1, violet's $2. Life's ordered: Org assists you."} and assumed you will write :macros { "macro_name" "macro-code"} , hence:

 :macros {
  "page-date" "<% current page %>"
}

… and it works when I call it with {{{page-date}}}

Thank you, Mentaloid and FlorianF !

Yes, I need the date to be fixed. It seems like this is a new area of knowledge for me. I need to learn how to edit the config.edn file first. It appears that date:: <% today % > is different from what I understood; I thought it represented the current date that remains unchanged.

I wish there was a variant of the macros that replaces itself with its value at first run … but that’s not the case…

If you are working from the journal file you’re good to go with the current page, as the name of the journal page is the current date and you get a clickable wikilink as the date:: value.

If you are working from a page then what @mentaloid suggested, namely a query for the created-date maybe should work but I have no idea how to call the query from the macro…

Never mind, I confused fixed with non-fixed.

As about the syntax of file config.edn, should look at edn format.

1 Like

If you have that in the template and you call the template the <% today %> gets replaced with today’s journal page link.
This is always the case no matter where the template is invoked.
In the same way you can also invoke specific days of the week (e.g. <% next friday %>)

Hope that sheds some light on that part of things :slight_smile:

2 Likes

@Siferiax I didn’t know it is this flexible, even these work:

  • <% one year from now %>
  • <% two weeks from now %>
  • <% one year ago %>

but for some reason replacing “now” with “today” doesn’t work anymore.

Yes it uses natural language dates.
https://docs.logseq.com/#/page/60312078-ae36-4395-bdfb-747304b80c03

1 Like

Some wishes are fortunate: Make custom macros that replace themselves with their value on first run

1 Like

It leads me down a new rabbit hole. In fact, I started learning Vim because of Logseq, and Vim enhances my Python learning. Then, I am overwhelmed by the knowledge, which takes me back to taking more notes on Logseq.

1 Like

You might want to take a look at this for using maros that replace themselves to readily access dynamic variables in Blocks as well as in Custom Commands: