Solved

Calculate Days from variable and compare

Posted on 2014-10-23
Medium Priority
63 Views
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);
}
``````
0
Question by:brendanlefavre
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 28

Expert Comment

ID: 40401200
This is easier if the dates are handled as Julian dates rather than Gregorian.
0

LVL 58

Accepted Solution

Julian Hansen earned 2000 total points
ID: 40401276
``````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');
}
``````
0

LVL 82

Expert Comment

ID: 40402685
``````var upcomingDate = moment(object["upcoming"]);
var cadenceWeekely = moment().diff(upcomingDate,'day') > 7;
``````
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be \$37.1B.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll