Open In App

Node.js date-and-time Date.isSameDay() Method

Last Updated : 26 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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.

  • By using npm:
npm install date-and-time --save
  • By using CDN link:
<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




// Node.js program to demonstrate the  
// Date.isSameDay() APi
  
// Importing http module
const date = require('date-and-time')
  
// Creating object of current date
// and time by using Date() 
const now1  =  new Date();
  
// Creating object of current date 
// and time using Date() method
const now2  =  new Date();
  
// Checking if both dates are same or not
// by using date.isSameDay() api
const value = date.isSameDay(now1,now2);
  
// Display the result
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




// Node.js program to demonstrate the  
// Date.isSameDay() APi
  
// Importing http module
const date = require('date-and-time')
  
// Creating object of current date 
// and time using Date() method
const now1  =  new Date();
  
// Creating object of current date and time 
// by using Date() method
const now2  =  new Date();
  
now1.setFullYear(2016)
  
// Checking if both dates are same or not
// by using date.isSameDay() method
const value = date.isSameDay(now1,now2);
  
// Display the result
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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads