Link to home
Start Free TrialLog in
Avatar of Asif Faleel
Asif FaleelFlag for United Arab Emirates

asked on

Calculate the Difference between 2 Date Fields as a Report In Dynamics CRM 2011

Hi,

I have 2 fields in My Opportunity form and i need to calculate the difference between the 2 dates for each Opportunity and produce a report or View.

Kindly help as to how i can achieve that.

Thanks,
Asif
Avatar of Anwar Saiah
Anwar Saiah

Depending on which scripting language you are using, there are available functions for calculating difference between two dates, in days hours years seconds whatever!
So kindly state what scripting language you are using, what kind of variables your two dates are, and in what form you want to see the difference between them.
Avatar of Asif Faleel

ASKER

Java Script.

Opportunity form.
You can use this custom function:
 function diffDays( date1, date2 ) {
  //Get 1 day in milliseconds
  var one_day=1000*60*60*24;

  // Convert both dates to milliseconds
  var date1_ms = date1.getTime();
  var date2_ms = date2.getTime();

  // Calculate the difference in milliseconds
  var difference_ms = date2_ms - date1_ms;
   
  // Convert back to days and return
  return Math.round(difference_ms/one_day);
}

this function should be included, then use:
var diff_in_days = diffDays(d1,d2);
Give me few days on this i will try it and let you know.
How do i exclude weekends while calculating the time difference.
ASKER CERTIFIED SOLUTION
Avatar of Anwar Saiah
Anwar Saiah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Done