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

To use the addBusinessDays function from the date-fns library in TypeScript, you first need to install the library using npm:

npm install date-fns
21 chars
2 lines

Then, you can import the function into your TypeScript file like this:

index.ts
import { addBusinessDays } from 'date-fns';
44 chars
2 lines

You can now use the addBusinessDays function in your code by passing in a date object and the number of business days you want to add to it:

index.ts
const today = new Date(); // get the current date
const twoBusinessDaysFromNow = addBusinessDays(today, 2); // add 2 business days to the current date
151 chars
3 lines

The addBusinessDays function works by skipping over weekends (Saturday and Sunday) when adding the specified number of business days. If you pass in a negative number as the second argument, it will subtract that many business days instead.

index.ts
const today = new Date(); // get the current date
const twoBusinessDaysAgo = addBusinessDays(today, -2); // subtract 2 business days from the current date
155 chars
3 lines

gistlibby LogSnag