Solved

Calculate Days from variable and compare

Posted on 2014-10-23
3
62 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 28

Expert Comment

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

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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 …
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.
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 learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 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