xxxxxxxxxx
let A = moment('2020-01-02');
let B = moment('2020-01-01');
let C = moment('2020-01-03');
console.log(A.diff(B, 'days'));// => 1
console.log(A.diff(C, 'days'));// => -1
xxxxxxxxxx
function check() {
var now = moment();
var hourToCheck = (now.day() !== 0)?17:15;
var dateToCheck = now.hour(hourToCheck).minute(30);
return moment().isAfter(dateToCheck);
}
console.log(check())
check if date is greater than 30 days
xxxxxxxxxx
let dateArr = myDataFromDb.map(d => d.date);
var maxDate = new Date(Math.max.apply(null, dateArr)); // max date
console.log(moment().diff(mDate, 'days')); // number of days
e.g // don't test with this data
[ // this is after the map
2021-08-10T00:00:00.000Z,
2023-02-15T00:00:00.000Z,
2021-09-09T00:00:00.000Z,
2022-01-27T00:00:00.000Z,
2023-02-12T00:00:00.000Z
]
// max here will be 2023-02-15T00:00:00.000Z
// use diff to get the days
// full code with moment
const moments = myDataFromDb.map(d => moment(d.date));
const maxDate = moment.max(moments);
if (moment().diff(maxDate, 'days') <= 30) {
// do your thing;
} else {
// do your thing;
}