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

To use the subBusinessDays function from the date-fns library in TypeScript, you first need to install the library using the following command:

index.ts
npm i date-fns
15 chars
2 lines

Then, you can import the function and use it in your code as shown below:

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

const currentDate = new Date('2021-12-22');
const daysToSubtract = 3;

const newDate = subBusinessDays(currentDate, daysToSubtract);
console.log(newDate); // Output: Mon Dec 20 2021 00:00:00 GMT+0530 (India Standard Time)
267 chars
8 lines

In the above code, we first import the subBusinessDays function from the date-fns library. Then, we create a currentDate variable representing the current date, and a daysToSubtract variable representing the number of business days to subtract from the current date.

Finally, we call the subBusinessDays function with currentDate and daysToSubtract as its arguments to get a new date with the specified number of business days subtracted from the current date.

gistlibby LogSnag