Solved

Calculate Days from variable and compare

Posted on 2014-10-23
3
56 Views
Last Modified: 2014-11-18
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"]);
var cadenceWeekely = upcomingDate.diff(moment().add(7, 'days'));

Open in new window


Then build up my application scope
                if (cadenceWeekely > timeIsNow) {
                       $scope.summary[segment].totalLateRelationships++;
                       $scope.summary[segment].lateRelationships.push(object);    
                }

Open in new window

0
Comment
Question by:brendanlefavre
3 Comments
 
LVL 23

Expert Comment

by:Dr. Klahn
Comment Utility
This is easier if the dates are handled as Julian dates rather than Gregorian.
0
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
Is this helpful?
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');
}

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
var upcomingDate = moment(object["upcoming"]);
var cadenceWeekely = moment().diff(upcomingDate,'day') > 7;

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now