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

To use the isSameDay function from date-fns library, first we need to install it via npm or yarn as follows:

npm install date-fns
21 chars
2 lines

or

yarn add date-fns
18 chars
2 lines

Then, we can import and use the function in our JavaScript code as shown below:

import { isSameDay } from 'date-fns';

const date1 = new Date('2021-10-01');
const date2 = new Date('2021-10-01');

console.log(isSameDay(date1, date2)); // Output: true

const date3 = new Date('2021-10-01');
const date4 = new Date('2021-10-02');

console.log(isSameDay(date3, date4)); // Output: false
303 chars
12 lines

The isSameDay function returns true if the two provided dates have the same day (and the same month and year), otherwise it returns false.

gistlibby LogSnag