1 Reply Latest reply on Sep 1, 2010 7:59 AM by pguerett

    FormCalc - Num2Date Question

    got-questions

      Hello,

       

      I am working on a simple form with calculating days. Basically, I need to add 7 years and 6 months onto a date entered by the user. Here is my current coding.

       

       

      if(HasValue(DateTimeField1)) then
      Num2Date( (Date2Num(SecA.DateTimeField1.formattedValue, "MM/DD/YYYY") + 2739), "MM/DD/YYYY")
      else
      null
      endif

       

      The problem is that it is slightly off due to leap years. I am adding the date by 2739 days because that is the closes to 7 years and 6 months. I am not sure if there is a Num2Date code that will solve the leap year problem. Thanks in advance.

        • 1. Re: FormCalc - Num2Date Question
          pguerett Level 6

          Th eonly thing I can suggest is that you use 365.25 days per year and this will give yo an additional 2 days in the calculation. This is not the most accurate but you will nly be out be a day at the worst.

           

          If you need something more accurate then I suggest that you do a web serach for "Date Calculations with Leap Years". There are a number of hits that will show you specifically how to do it.

           

          Paul