Dataview - Display Age in Days Before each Task

What I’m trying to do

I am currently displaying a list of all non completed tasks

Using the following code

# Open Tasks
```dataview
TASK
WHERE !completed AND !checked
SORT file.ctime asc

I would like to add the age in days for each non completed task before the task, so:

o  Configure Obsidian on Laptop

Would display as:

o  [2d] Configure Obsidian on Laptop

Assuming that the task has been open and non completed for 2 days now.

I can calculate the age in days, I am just not sure how to add it to the task line, or create a second column which would display it.

Any suggestions / code examples would be greatly appreciated.

Thanks in advance.

The trick to this kind of query is to use FLATTEN ... as Visual. Then it’ll display this text instead of the ordinary text, whilst still keeping the ordinary task linkage.

So in your case try something like:

TASK
WHERE !completed AND !checked
FLATTEN 
  "[" + (date(today) - file.cday).days + "d] " 
  + text as visual
SORT file.ctime asc
```

Which in my test scenario output this amongst a whole bunch of other not completed tasks:
image

If you want to you could also include the text in <span> elements and style them. One variant using this trickery:

```dataview
TASK
WHERE !completed AND !checked
FLATTEN 
  "<span style='background-color: teal; font-size: 70%; vertical-align: top'>["
  + (date(today) - file.cday).days
  + "d]</span>&nbsp;&nbsp; " 
  + text as visual
SORT file.ctime asc
```

Which displays the same segment as in previous image:
image

Hope this helps! Do note that using file.ctime and/or file.cday could be slightly unreliable depending on your sync regime, and other file system dependent stuff, and that in any case it’ll refer to the file date, not when you added/changed any given task in that file.

@holroy Thank you so very much, that was perfect. I had tried something similar, just missing some key elements.

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