Solved

Calculate Days from variable and compare

Posted on 2014-10-23
3
60 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 25

Expert Comment

by:Dr. Klahn
ID: 40401200
This is easier if the dates are handled as Julian dates rather than Gregorian.
0
 
LVL 54

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 40401276
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
ID: 40402685
var upcomingDate = moment(object["upcoming"]);
var cadenceWeekely = moment().diff(upcomingDate,'day') > 7;

Open in new window

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

816 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