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

To use the previousDay function from the date-fns library in TypeScript, first install the date-fns library:

index.ts
npm install date-fns
21 chars
2 lines

Then, import the function and use it in your TypeScript code:

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

const today = new Date();
const yesterday = previousDay(today);
console.log(yesterday); // Outputs the date of yesterday in your local timezone
185 chars
6 lines

Note that the previousDay function takes a Date object as its argument and returns a new Date object, so make sure to properly handle the return value. Additionally, you may also need to install TypeScript types for the date-fns library if you haven't already:

index.ts
npm install @types/date-fns
28 chars
2 lines

gistlibby LogSnag