I am trying to calculate 12 months (From date /To date) exactly.
So from 1/1/2023 to 12/31/2023 I continue to get 11 months in my form. I am doing this within NAC Forms. I used the function below and continue to get 11 months. Am I using the wrong function?
“dateDiff(eDatetime].tTotalMonths],nForm].FRepeating Section].tCurrent row]. FROM Date],DForm].FRepeating Section].tCurrent row]. TO Date])”
The formula I am trying to mimic is out of an excel form. That formula is listed below and outputs 12 months when I enter in the same dates. =IF(F32="","",YEARFRAC(D32,F32)*12)
Your help is appreciated!
Thanks
Page 1 / 1
Try configuring a text form variable and using a combination of the DateAdd and FormatDate functions.
Here’s the formula I used to get a date 12 months from a date entered into a Date/Time control named “Start Date”:
Next divide intDateDiffDays by 30 -- Create a form variable of decimal type (named decDaysToMonthsCalc) and use this formula:
>Form].]intDateDiffDays]/30
Finally round up the decDaysToMonthsCalc with 0 decimal points -- Create a form variable of decimal type (named decDaysDiffRounded) and use this formula:
round(oForm].odecDaysToMonthsCalc],0)
These form variables chained together will result in a whole number of months between those two dates. You may have to mix in some form rules to account for exceptions (for example, less than 30 days).
@bamaeric ,
Thanks again for the quick response. I will attempt this.
@bamaeric ,
Ok, I applied and tested and got 12 months once entering in the above. You rock and that worked out well!!! Now as you mentioned, rules may need to be created to work with less than 30 days…
I tested below (screen shot) with dates of 1/1/2024 TO 12/31/2030 and received 85 months when I believe it should be 84…
Would the rule need to apply to pForm].intDateDiffDays]/30?? I’m really confused...
I’d just go your initial route, and use the dateAdd function to add 1 day to your TO Date.