1 Reply Latest reply on Feb 24, 2017 7:18 PM by KayDobe

    Calculate end date from start date and radio button values


      Using FormCalc, I wish to calculate from a user entered start date, adding 90, 180 or 365 days to get to get an end date. I am using radio buttons for the 90, 180 and 365 days.  So far I have this:



      (radioButton.rawValue==1)//radio button bound to 1 is on/yes then;//


      and I have this:







      = newDate


      but I don't know how to put them together or incorporate the 180 and 365 days.  I know the second part works because I currently use it, but that is as far as I have gotten.


      Any help/suggestions will be greatly appreciated!!!




      Lou Johnson



        • 1. Re: Calculate end date from start date and radio button values
          KayDobe Level 1

          Take a look at this answer I gave another person about adding days to dates: Re: Adding Days to a Date.


          So, depending on whatever value the user picks from the radio button (90, 180, 365), add that number to a periodSelect variable, then run a  Num2Date call to set the value of the newDate field.  The example below presumes you have a radio button called radioButton1 with default button values of '0' for 90 days, '1' for 180 days, and '2' for 365 days.




          var periodSelect

          var newDate_Num


          if (radioButton1.rawValue == "1") then

              periodSelect = 180

          elseif (radioButton1.rawValue == "2") then

              periodSelect = 365


              periodSelect = 90



          newDate_Num = Date2Num(Start_Date.formattedValue, "YY/DD/YYYY") + periodSelect

          newDate.rawValue = Num2Date(newDate_Num, "YY/DD/YYYY")



          Caveat to using .rawValue versus .formattedValue when it comes to date fields (something I had to figure out/learn on my own the hard way): .rawValue will be zero if the user clicks in the date field and picks via the drop-down calendar rather than types it in.  My best guess is that happens because the calendar drop-down box mouseclick isn't a date, but a window coordinate that the subroutine has to convert into a date for the .formattedValue.


          Hope this helps.


          - Kaye