Moment.js Check a date is today
You can use the startOf
and isSame
methods together to achieve your goal here.
Running startOf('day')
on a moment object will set that moment to - you guessed it - the start of the day it occurs on. If you convert each of your timestamps using this method you can easily compare them to one another using isSame()
.
For example:
var today = moment(1406019110000);
var yesterday = moment(1405951867000);
if (today.startOf('day').isSame(yesterday.startOf('day'))) {
// They are on the same day
} else {
// They are not on the same day
}
You can try this
moment().isSame(moment(timestamp), 'day')
You can use isSame()
, limiting the granularity to a day:
var today = moment(1406019110000);
var yesterday = moment(1405951867000);
if (today.isSame(yesterday, 'd')) {
// They are on the same day
} else {
// They are not on the same day
}