Solved

Calculate Days from variable and compare

Posted on 2014-10-23
3
59 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 24

Expert Comment

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

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

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rhino JavaScript import, load 25 67
Facebook React and SyntheticEvents 6 49
Angular - following an example but mine partly works 17 45
Split in Javascript 5 31
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

910 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

25 Experts available now in Live!

Get 1:1 Help Now