locked
CRM 4.0 - Calculate number of days RRS feed

  • Question

  • Hi,

    Does anyone know of a form script I can use to calculate the number of days between today and an expiry date which I have created as a field in the Accounts form in CRM?

    I have set up an Int field called No. of Days.

    Many thanks in advance! 
    Monday, March 30, 2009 1:30 PM

Answers

  • Something like this:

    function dateDifference(strDate1, strDate2)
    {
         datDate1= Date.parse(strDate1);
         datDate2= Date.parse(strDate2);
         return (datDate2-datDate1)/(24*60*60*1000);
         
    }

    var now = new Date();
    crmForm.all.myfield.DataValue = dateDifference(crmForm.all.datefield.DataValue, now);
    • Marked as answer by Tizzy22 Monday, March 30, 2009 3:06 PM
    Monday, March 30, 2009 1:53 PM

All replies

  • Something like this:

    function dateDifference(strDate1, strDate2)
    {
         datDate1= Date.parse(strDate1);
         datDate2= Date.parse(strDate2);
         return (datDate2-datDate1)/(24*60*60*1000);
         
    }

    var now = new Date();
    crmForm.all.myfield.DataValue = dateDifference(crmForm.all.datefield.DataValue, now);
    • Marked as answer by Tizzy22 Monday, March 30, 2009 3:06 PM
    Monday, March 30, 2009 1:53 PM
  • Thanks for that Daniel, much appreciated!  However I have never done this before and am pretty stuck as to what fields to add where.  Also, what do I use for Today?

    Is this anywhere near right??

    function dateDifference(new_expirydate, strDate2)
    {
         datDate1= Date.parse(new_expirydate);
         datDate2= Date.parse(strDate2);
         return (datDate2-new_expirydate)/(24*60*60*1000);
         
    }

    var now = new Date();
    crmForm.all.new_noofdaystorenewal.DataValue = dateDifference(crmForm.all.datefield.DataValue, now);


    Monday, March 30, 2009 2:37 PM
  • Daniel,

    I've sorted it.  Thanks very much for the script!!!

    Cera
    Monday, March 30, 2009 3:06 PM