Get all tasks due on date where date is based on filename

What I’m trying to do

I want to show all tasks that are due today, where today is defined by the file name.
The following line works, however, if I open a daily note file for a future day, it will of course show the tasks due today.:

due on <% tp.date.now("YYYY-MM-DD") %>

I tried the following codes in a file with the name “2022-05-18” (without quotation marks)

due on <% tp.file.title %>
due on <% tp.file.name %>
due on <% file.name %>

I get the following message:
“Tasks query: do not understand due date”

On a side note: how can I read the output of the function, lets say “tp.file.title” to better understand why the due date is not understood?

If you put something like <% tp.file.title %> on a line that is outside of any code block (no triple-ticks around it) and then run the command "Templater: Replace templates in the active file" from your Command Palette, you can see the output. (I have this command mapped to a hotkey because I use it frequently.) Have you been running this command when you were testing <% tp.file.title %> in your tasks query before?

You may not need it for this example, but to answer the general question, you can optionally send a reference date to tp.date.now, per the templater documentation. For example:

tp.date.now("YYYY-MM-DD", reference = tp.file.title, reference_format = "YYYY-MM-DD");

I’m not sure that reference_format bit is necessary since you are in the default format, maybe you can test and find out? :slight_smile:

Thanks. Works great.

The code works without reference_format in my case :slight_smile:

1 Like

Thanks, now we’ve both learned something! :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.