To use the subyears function from date-fns library in Javascript, you need to first install the library through npm:
index.tsx21 chars2 lines
Once installed, you can import and use the subYears function as follows:
index.tsx346 chars9 lines
The subYears function takes two parameters:
date: a Date object representing the date you want to subtract years fromyears: the number of years you want to subtractIn the example above, we subtracted 1 year from someDate, which resulted in a new Date object representing March 1, 2021.
gistlibby LogSnag