Query tasks by deadline

I am trying to add a query to my daily journal template that will display any tasks where deadline <= {{today}} but that doesn’t seem to be working

task where deadline <= {{today}} and not done render [[Library/Core/Query/Task]] 

How should I properly format the query?

Wrap {{today}} in quotes.

Example:

task render [[Library/Core/Query/Task]]
where deadline <= "{{today}}" and not done

Another way is to just call the function directly instead of using {{}} such as the following which I do:

task where deadline <= today() and not done render [[Library/Core/Query/Task]]
1 Like

@i_am_dangry @dklawren Thank you both very much!!!

I have not checked if results come up ordered by deadline on their own, but when I set up my queries I had added “order by deadline” anyway.

How did you add that? before the render? after? it appears they are ordered by the date created.

Here is my query, which only presents deadlines for the following seven days:

task where deadline <= "{{nextWeek}}" and deadline > "{{today}}" and done = false order by deadline render [[template/tasks]] 
1 Like

For style reasons I’d really prefer you use less of the “{{nextWeek}}” and more of the nextWeek(). Looks nicer no?

2 Likes

I need at some point to sit down and catch up to how things have changed, since I set up my queries a year and a half ago.

It does look way better though :grin:

The old way was when we still used handlebars as template engine. With templates 2.0 things got dramatically nicer. Join the future!

3 Likes

I might be missing something, but I tried to join the future and the downside of today() over {{today}} in templates is {{today}} is rendered into a date when the template is called, but today() isn’t, so my query will constantly update to the current date rather than freeze on the date the page was generated. I could go through and click bake on those queries, but I’m too lazy for that.

Ah yes, for that use case the {{today}} notation is what you want

1 Like