[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1455
  • Last Modified:

Sage CRM Javascript Date Difference

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
BowTech
Asked:
BowTech
  • 3
  • 2
2 Solutions
 
Nathan BoveSoftware EngineerCommented:
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
 
leakim971PluritechnicianCommented:
@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
 
BowTechAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
BowTechAuthor Commented:
Ah, I stand corrected. The result is negative, so I'll need to accommodate that.
0
 
leakim971PluritechnicianCommented:
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
 
BowTechAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now