Calculated dates in queries (templates)

I wanted to have this to add previous and next buttons to my weekly notes, and came up with this snippet:

```space-script
silverbullet.registerFunction("addDays", (date, days) => {
  const plainDate = Temporal.PlainDate.from(date);
  const offsetDate = plainDate.add(Temporal.Duration.from({ days: Number(days) }));
  return offsetDate.toString();
});
```

You can use it like this, unless you want to pass a negative number:

{{addDays(today, 7)}}

Once I have a few more things I think I would publish with a Library, since I’m already running six SiverBullet instances for family and friends.

3 Likes