Solved

Calculate Days from variable and compare

Posted on 2014-10-23
3
61 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
[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
  • Learn & ask questions
3 Comments
 
LVL 27

Expert Comment

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

726 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