Add number of days to date [in dataviewJS]

What I’m trying to do

I just want to add (subtract) a number of days to a given date (in format: YYYY-MM-DD).
I probably can’t see the wood for the trees again…

Things I have tried

my inline dataview looks like:
=dateformat((this.PstartDate - date(today)) - dur(21 days), "yyyy.MM.dd")

but this is all
Dataview (for inline query '[object Object]'): No implementation of 'dateformat' found for arguments: duration, string

the duration is displayed correctly via:
=(this.PstartDate - date(today)) - dur(21 days)

1 Monat, 1 Woche und 4 Tage

but I want the date, not the duration

How to set the syntax properly, or have I to use dataviewJS for this?

Thanks in advance

i fiddled around, but something is wrong with the difference.

if I set the PstartDate to 2023-07-15 and give them a duration of 4 days, then my code seems to work:

=date(today) + dur(string(((this.PstartDate - date(today)).days - 4))+"days")


but when i testwise set the PstartDate to 2023-09-19
then the tin head calculates

what should have been 2023-09-15

Can someone bring me to enlightenment?

Not what you want, but as a simplistic method does the following help diagnostically at all?

- PstartDate:: 2023-07-15
- Days:: 5 days

## query Days Plus
`= this.PstartDate + this.Days`

## query Days Minus
`= this.PstartDate - this.Days`

inline dv queries are slow to update; might need to navigate away from and then back to the specific page

I imagine other users will have better solutions to offer, but until then …

Thank you very much.
yes, the difference between the dates is now correct.
the devil knows, why my code does not work correctly…

inline dv queries are slow to update; might need to …

yes, you have to change the focus…
would this be better (cleaner) solved with datatviewJS?

1 Like

Probably, yes, but I know almost nothing about Dataview JS. Hope someone else can help.

1 Like