No problem, I’m confused myself when navigating this landscape of dates in different contexts.
Within dvjs, this
becomes dv.current()
, so this.file.day
should be dv.current().file.day
. ( This will give a DateTime
object (which is not the same as a moment()
date object. ))
Within moment()
we can’t use Dataview dates (aka DateTime
object) directly, we need to convert them using .toISODate()
(or similar) when passed to a constructor of moment()
(or something which accepts the same parameters as a constructor).
So dvjs can extract dates from file names and YAML keys, but the syntax differs, and when used in combination with moment()
you need to translate the date variables even a little more.
So your example therefore becomes:
`$= moment(dv.current().file.day.toISODate()).diff(dv.current().birthday.toISODate(), 'years')`
And if you use just moment()
it’ll give todays date, but to display it you would typically do something like: `$= moment().format(“YYYY-MM-DD”) `
.