[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Sage CRM Javascript Date Difference

Posted on 2011-03-24
6
Medium Priority
?
1,440 Views
Last Modified: 2012-05-11
Trying to determine the number of months between two dates in Sage CRM. If the difference is more than 6 months, I need to notify the user.  CRM stores the date as "mm/dd/yyyy", but the js Date() function returns "Thu Mar 24 12:37:56 CDT 2011" (for example).  So with the two different formats, this doesn't work.

<script language="javascript">
window.attachEvent('onload', ShowMyAlert);

function ShowMyAlert()
{
  if(!document.getElementById("comp_name"))
  {
    var myDate = document.getElementById('_Datacomp_info_upd_ox').innerText;

   var myToday=new Date();

   var myMsg = "Company Record Needs Verification";

   var myDiff = dateDiff(myToday,myDate);

   if(myDiff > 180)
{
    alert(myMsg);
}
  }
}

function dateDiff(d1,d2) {
   diffMilli = d2.getTime()-d1.getTime();
   return diffMilli/(1000*60*60*24)
}

</script>
0
Comment
Question by:BowTech
[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
  • 2
6 Comments
 
LVL 7

Assisted Solution

by:nbove
nbove earned 800 total points
ID: 35209955
I think the problem is that your "myDate" variable is a string and not a date.  Trying modifying the declaration of your myDate variable to the following:
var myDate = new Date(document.getElementById('_Datacomp_info_upd_ox').innerText);

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 1200 total points
ID: 35212054
@nbove is right, another one :

function ShowMyAlert() {
		if(!document.getElementById("comp_name")) {
			var myDate = document.getElementById('_Datacomp_info_upd_ox').innerText;
			
			myDate = myDate.split("/");
			myDate = new Date(myDate[2], myDate[0]-1, myDate[1]);

			var myToday = new Date();
			var myMsg = "Company Record Needs Verification";
			var myDiff = dateDiff(myToday,myDate);
			if(myDiff > 180) {
				alert(myMsg);
			}
		}
	}

Open in new window

0
 

Author Comment

by:BowTech
ID: 35218342
Thanks for the responses, but neither of these appears to catch the date. I'm wondering if the dateDiff function is out of scope (I'm not familiar with Javascript).

<script language="javascript">
window.attachEvent('onload', ShowMyAlert);

function ShowMyAlert()
{
  if(!document.getElementById("comp_name"))
  {
      var myDate = document.getElementById('_Datacomp_info_upd_ox').innerText;
                  
      myDate = myDate.split("/");
      myDate = new Date(myDate[2], myDate[0]-1, myDate[1]);

      var myToday = new Date();
      var myMsg = "Company Record Needs Verification";
      var myDiff = dateDiff(myToday,myDate);
      if(myDiff > 180) {
            alert(myMsg);
      }
  }
}

function dateDiff(d1,d2)
{
   diffMilli = d2.getTime()-d1.getTime();
   return diffMilli/(1000*60*60*24)
}


</script>
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:BowTech
ID: 35218408
Ah, I stand corrected. The result is negative, so I'll need to accommodate that.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35218454
Yes,

      if(myDiff > 180) {
            alert(myMsg);
      }
      else {
           alert("<0");
      }

Open in new window


some good links (don't forget to vote for the first one) :
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_484-Can-I-have-a-date.html
http://www.w3schools.com/jsref/jsref_obj_date.asp
0
 

Author Comment

by:BowTech
ID: 35218556
I just changed the polarity of the dateDiff return value.  We're good. Thanks all!


function dateDiff(d1,d2)
{
   diffMilli = d2.getTime()-d1.getTime();
   return -diffMilli/(1000*60*60*24)
}

</script>
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

649 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