MomentJS - Is Same or Before


Advertisements

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

Is

Example

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

Output

isSameOrBefore

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

isSameOrBefore Method

Example

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

Output

isSameOrBefore Month
momentjs_date_queries.htm
Advertisements