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

To use the endOfYesterday function from the date-fns library in TypeScript, you need to first install the library using npm or yarn.

npm install date-fns
# or
yarn add date-fns
44 chars
4 lines

Then, you can import the endOfYesterday function and use it in your code like this:

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

const yesterdayEnd = endOfYesterday();
console.log(yesterdayEnd); // Output: Tue Oct 05 2021 23:59:59 GMT+0100 (British Summer Time)
177 chars
5 lines

The endOfYesterday function returns a Date object representing the end of yesterday, which is the last moment of the day before today. You can then use this object to perform any date/time operations you need.

Note: The date-fns library provides many other useful functions for working with dates and times, so be sure to check out its documentation.

gistlibby LogSnag