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

To use the previousTuesday function from the date-fns library in JavaScript, first install the library via npm:

npm install date-fns
21 chars
2 lines

Then, import the function into your code and use it like so:

import { previousTuesday } from 'date-fns';

const date = new Date(); // create a new Date object

const previousTuesdayDate = previousTuesday(date); // get the previous Tuesday date object

console.log(previousTuesdayDate); // log the previous Tuesday's date object to the console
282 chars
8 lines

The previousTuesday function takes in a date object and returns a new date object representing the previous Tuesday relative to the input date.

gistlibby LogSnag