Node.js date-and-time Date.isSameDay() Method
Last Updated :
26 Mar, 2021
The date-and-time.Date.isSameDay() method is used to check if the given dates are the same or not.
Required Module: Install the module by npm or used it locally.
npm install date-and-time --save
<script src="/path/to/date-and-time.min.js"></script>
Syntax:
isSameDay(date1, date2)
Parameters: This method takes the following parameters-
- date1: It holds the Object of date1.
- date2: It holds the Object of date2.
Return Value: This method returns the Boolean value true if and only if both the dates are the same.
Example 1:
index.js
const date = require( 'date-and-time' )
const now1 = new Date();
const now2 = new Date();
const value = date.isSameDay(now1,now2);
if (value)
console.log( "Both dates are same" )
else
console.log( "Both dates are not same" )
|
Run index.js file using below command:
node index.js
Output:
Both dates are same
Example 2:
Javascript
const date = require( 'date-and-time' )
const now1 = new Date();
const now2 = new Date();
now1.setFullYear(2016)
const value = date.isSameDay(now1,now2);
if (value)
console.log( "Both dates are same" )
else
console.log( "Both dates are not same" )
|
Run index.js file using below command:
node index.js
Output:
Both dates are not same
Reference: https://github.com/knowledgecode/date-and-time#issamedaydate1-date2
Share your thoughts in the comments
Please Login to comment...