I'm trying to determine whether there are more than 7 days between two dates using moment.js.
code:
var start = moment(self.StartDate(), "DD/MM/YYYY");
var end = moment(self.EndDate(), "DD/MM/YYYY");
console.log(start);
console.log(end);
console.log(moment.duration(end.diff(start)).asDays());
if (moment.duration(end.diff(start)).asDays() > 7) {
alertify.alert("Error", "Only a maximum of 7 days can be investigated.");
return;
}
This works if the two dates are within the same month. However, if the dates cross over between 2 months the duration
returns a negative value.
Example results: