how to use the subminutes function from the date-fns library in typescript

To use the subMinutes function from the date-fns library in TypeScript, you first need to install the library and its types via npm:

index.ts
npm install date-fns 
npm install -D @types/date-fns
53 chars
3 lines

After installing the library and its types, you can import the subMinutes function and use it to subtract a specified number of minutes from a given date:

index.ts
import { subMinutes } from 'date-fns';

const now = new Date(); // current date and time
const tenMinutesAgo = subMinutes(now, 10); // subtract 10 minutes from current date and time
182 chars
5 lines

In this example, we imported the subMinutes function from the date-fns library and used it to subtract 10 minutes from the current date and time, resulting in a new date representing the time 10 minutes ago.

Note that the subMinutes function returns a new date object and does not modify the original date object.

gistlibby LogSnag