Moment.js isSameOrAfter() Function - GeeksforGeeks

24 Jul, 2020
It is used to check whether a date is the same or after a particular date in Node.js using the isSameOrAfter() function that checks if a moment is after or the same as another moment. The first argument will be parsed as a moment, if not already so.
Syntax:
moment().isSameOrAfter(Moment|String|Number|Date|Array);
moment().isSameOrAfter(Moment|String|Number|Date|Array, String);

Parameter: It can hold Moment|String|Number|Date|Array.
Returns: True or False
Installation of moment module:
You can visit the link to Install moment module. You can install this package by using this command.npm install momentAfter installing the moment module, you can check your moment version in command prompt using the command.npm version momentAfter that, you can just create a folder and add a file for example, index.js. To run this file you need to run the following command.node index.js
You can visit the link to Install moment module. You can install this package by using this command.npm install moment
npm install moment
After installing the moment module, you can check your moment version in command prompt using the command.npm version moment
npm version moment
After that, you can just create a folder and add a file for example, index.js. To run this file you need to run the following command.node index.js
node index.js
Example 1: Filename: index.js
// Requiring moduleconst moment = require('moment');  var bool1 = moment('2010-10-20')    .isSameOrAfter('2010-10-21');  // falseconsole.log(bool1);  var bool2 = moment('2010-10-20')    .isSameOrAfter('2010-10-20');  // trueconsole.log(bool2);  var bool3 = moment('2010-10-20')    .isSameOrAfter('2010-10-19');  // trueconsole.log(bool3);
Steps to run the program:
The project structure will look like this:Make sure you have installed moment module using the following command:npm install momentRun index.js file using below command:node index.jsOutput:false
true
true

The project structure will look like this:
Make sure you have installed moment module using the following command:npm install moment
npm install moment
Run index.js file using below command:node index.jsOutput:false
true
true

node index.js
Output:
false
true
true

Example 2: Filename: index.js
// Requiring moduleconst moment = require('moment');  function checkIsSameOrAfter(date1, date2) {   return moment(date1).isSameOrAfter(date2);  }  var bool = checkIsSameOrAfter(    '2010-10-20', '2010-10-20');  // trueconsole.log(bool);
Run index.js file using below command:
node index.js
Output:
true

Reference: https://momentjs.com/docs/#/query/is-same-or-after/
Moment.js
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to connect Node.js with React.js ?
Difference between dependencies, devDependencies and peerDependencies
Node.js Export Module
Mongoose Populate() Method
Mongoose find() Function
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Difference between var, let and const keywords in JavaScript