Count how many years and months separately have a date until today (now)

If i have a date like 2021-01-01 how i can calculate in two diff text inputs how much years have been passed until now and how many months?

i use postgresql

thank you

The pre-loaded Moment library has some useful functions for this:
{{ moment(date1.value).diff(Date.now(),'days') }}
or
{{ moment(date1.value).diff(Date.now(),'hours') }}

https://momentjs.com/docs/#/displaying/difference/

that works for days, but i need years and months, i can use months and years as i saw in that doc right?

in addition, how to remove the - negative before number?

got it i just inverted vars {{ moment(Date.now()).diff(fechaingresolaboral.value,'years') }} works good, thank you

1 Like