Easiest way to implement "days since" or "days till" counters?

Hi all,

I think my title describes what I’m looking for, basically a simple way to include things like “days since I last did x” or “days till y” in my notes, where that part of the note would reference a specific calendar date (I don’t necessarily need stored variables).

Would JavaScript via Templater or Data View make sense for this, for example? If so, what exactly do I need to do?

Thanks in advance.

2 Likes

Hi. Can you clarify better with a typical example of what you want? Are you talking about tasks? Queries in daily note templates? A fixed date, durations from “today” date, …?
Only with an example is possible to indicate if Dataview or Templater works for what you want.

Hi, thanks for your reply.

An example, let’s say I’m leaving for vacation on December 20th (of this year). How could I show a dynamic answer of how many days that is from today?

The solution also depends if this is an isolated need or if it’s a more structured request with implications in the way you compose your notes.
Let’s try the second case (a more ‘structured’ way).
Let’s say you have a note for your “December vacations” and other for your friend “John birthday”.
In these notes you need to create a field with the date. For dataview plugin you can create this field in two ways: in yaml frontmatter with the syntax key: value; or an inline-field with the syntax key:: value. (here I’ll use the second type of field - inline field)

December vacations

# December vacations

duedate:: 2021-12-20

---

This is my note about my next vacations in December.

John birthday

# John birthday

duedate:: 2022-01-15

---

This is my note about the next John birthday

Now, you can work with this data field in multiple ways.


Case 1

You want a main note with the “countdown” for important events. In particular, you want a list/table with a panoramic view to all the next ‘big’ dates.
You can create this query:

## Next events

```dataview
TABLE duedate, duedate - date(today) AS "Remaining days"
WHERE duedate AND duedate >= date(today)
```

This is the result (ignore the date format - it’s my os language):


Case 2

You want write a note with the dynamic value somewhere in your text… Something like:

«I need to buy train tickets because I only have x days for the december vacations.»

In this case you want the “x days” as dynamic value. For this you can write this:

I need to buy train tickets because I only have `=[[December vacations]].duedate - date(today)` for the december vacations.

The result:


11 Likes

Thank you for this incredibly detailed answer. This answered my question and taught me a lot more besides. I was just starting to explore Dataview after I posted this. Really inspired by the possibilities. Thanks again.

2 Likes

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