# Calculate Days from variable and compare

I'm trying to calculate if an event is greater than today with a date passed in from a variable plus 7 days

example: Today is less than variable date + 7 days

Variables:
``````var timeIsNow = moment('MM-DD-YYYY');
var upcomingDate = moment(object["upcoming"]);
``````

Then build up my application scope
``````                if (cadenceWeekely > timeIsNow) {
\$scope.summary[segment].totalLateRelationships++;
\$scope.summary[segment].lateRelationships.push(object);
}
``````
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Principal Software EngineerCommented:
This is easier if the dates are handled as Julian dates rather than Gregorian.
Commented:
``````var _MS_PER_DAY = 1000 * 3600 * 24;

function DateDaysDiff(date)
{
var compare = new Date(date);
var today = new Date();
var timediff = today.getTime() - compare.getTime();
var days = Math.ceil(timediff / _MS_PER_DAY);
return days;
}
...
if (DateDaysDiff('2014-10-20') > 7) {
alert('Date is more than 7 days ago');
}
``````

Experts Exchange Solution brought to you by

``````var upcomingDate = moment(object["upcoming"]);