To use the differenceInMinutes()
function from the date-fns library in TypeScript, first, we need to install the library by running the following command.
21 chars2 lines
Then, we import the differenceInMinutes()
function in our TypeScript file like this:
index.ts48 chars2 lines
After that, we can use the differenceInMinutes()
function to find the difference between two dates in minutes. Here's how we can use it:
index.ts235 chars6 lines
This will output:
index.ts154 chars2 lines
Note that the differenceInMinutes()
function returns a negative value if date1
is after date2
. To get a positive value, simply reverse the order of the arguments.
gistlibby LogSnag