Moment JS - check if a date is today or in the future

You can use the isSame function:

var iscurrentDate = startTime.isSame(new Date(), "day");
if(iscurrentDate) {

}

Since no one seems to have mentioned it yet, the simplest way to check if a Moment date object is in the past:

momentObj.isBefore()

Or in the future:

momentObj.isAfter()

Just leave the args blank -- that'll default to now.

There's also isSameOrAfter and isSameOrBefore.

N.B. this factors in time. If you only care about the day, see Dipendu's answer.


After reading the documentation: http://momentjs.com/docs/#/displaying/difference/, you have to consider the diff function like a minus operator.

                   // today < future (31/01/2014)
today.diff(future) // today - future < 0
future.diff(today) // future - today > 0

Therefore, you have to reverse your condition.

If you want to check that all is fine, you can add an extra parameter to the function:

moment().diff(SpecialTo, 'days') // -8 (days)

// Returns true if it is today or false if it's not
moment(SpecialToDate).isSame(moment(), 'day');

Tags:

Momentjs