
- 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 - Is Same or Before
This method checks if a moment is same or before another moment.
Syntax
moment().isSameOrBefore(Moment|String|Number|Date|Array); moment().isSameOrBefore(Moment|String|Number|Date|Array, String);
Example
var issameorbefore = moment('2017-10-10').isSameOrBefore('2017-11-21');
Output

Example
var issameorbefore = moment('2017-10-10').isSameOrBefore('2017-08-21');
Output

Observe that in the code shown above, the moment is neither the same nor before, so output is false.
We can use the units with isSameOrBefore() and the ones supported are year, month, week ,day, hour, minute and second.
Example
var issameorbefore = moment('2017-10-10').isSameOrBefore('2017-08-21', 'year');
Output

Example
var issameorbefore = moment('2017-10-10').isSameOrBefore('2017-10-21', 'month');
Output

momentjs_date_queries.htm
Advertisements