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

To use the nextFriday() function from the date-fns library in TypeScript, you can follow these steps:

  1. Install the date-fns library by running the following command in your terminal:
npm install date-fns
21 chars
2 lines
  1. Import the nextFriday() function from the date-fns library at the top of your TypeScript file:
index.ts
import { nextFriday } from 'date-fns';
39 chars
2 lines
  1. Use the nextFriday() function in your code to get the date of the next Friday:
index.ts
const today = new Date(); // get today's date
const nextFriday = nextFriday(today); // get the date of the next Friday
console.log(nextFriday); // e.g. Fri Dec 17 2021 00:00:00 GMT-0500 (Eastern Standard Time)
210 chars
4 lines

Note: You can pass an optional second argument to the nextFriday() function to indicate the week start, default is Monday. For instance, calling nextFriday(today, {weekStartsOn: 0}) returns the date of the next Friday using Sunday as the week start.

gistlibby LogSnag