![MomentJS Tutorial](/momentjs/images/momentjs-mini-logo.jpg)
- MomentJS Tutorial
- MomentJS - Home
- MomentJS - Overview
- MomentJS - Environment Setup
- MomentJS - Introduction
- MomentJS - Parsing Date And Time
- MomentJS - Date Validation
- MomentJS - Getter/Setter
- Manipulate Date And Time
- Formatting Date And Time
- MomentJS - Date Queries
- MomentJS - Internationalization
- MomentJS - Customization
- MomentJS - Durations
- MomentJS - Utilities
- MomentJS - Plugins
- MomentJS - Examples
- MomentJS Useful Resources
- MomentJS - Quick Guide
- MomentJS - Useful Resources
- MomentJS - Discussion
MomentJS - Is Same
This method will check if the moment is same as another moment. It returns true or false.
Syntax
moment().isSame(Moment|String|Number|Date|Array); moment().isSame(Moment|String|Number|Date|Array, String);
Example
var issame = moment([2015, 10, 01]).isSame([2015, 10, 01]);
Output
![Is Same](/momentjs/images/is_same.jpg)
Note that as with isBefore, we can use unit with isSame() method. Following are the units supported: year, month, week, day, hour, minute and second.
Example
var issame = moment([2015, 10, 01]).isSame([2015, 05, 10], 'year');
Output
![isBefore](/momentjs/images/isbefore.jpg)
Since the year of both moments is matching, it gives true as the output.
Example
var issame = moment([2015, 10, 01]).isSame([2015, 05, 10], 'month');
Output
![Same Moments](/momentjs/images/same_moments.jpg)
Note that in the above example the month is not matching, so it gives the output as false.
You will get false for month unit even if the year is not matching. Observe the following code for the same.
Example
var issame = moment([2015, 10, 01]).isSame([2014, 05, 10], 'month');
Output
![Same Not Matching](/momentjs/images/same_not_matching.jpg)
Example
var issame = moment([2015, 10, 01]).isSame([2015, 05, 10], 'day');
Output
![Same Day](/momentjs/images/same_day.jpg)
momentjs_date_queries.htm
Advertisements