how to use the previousfriday function from date-fns in javascript

To use the previousFriday function from the date-fns library in JavaScript, you can follow these steps:

  1. Install the date-fns package using npm or yarn.
npm install date-fns
# or
yarn add date-fns
44 chars
4 lines
  1. Import the previousFriday function from the date-fns package.
index.tsx
import { previousFriday } from 'date-fns';
43 chars
2 lines
  1. Call the previousFriday function with a date parameter to get the previous Friday from that date.
index.tsx
const date = new Date('2022-01-25'); // Tuesday, January 25, 2022
const previousFriday = previousFriday(date); // Friday, January 21, 2022
139 chars
3 lines

Note that the previousFriday function returns a new Date object representing the previous Friday from the specified date.

gistlibby LogSnag