Skip to main content
Nintex Community Menu Bar
Solved

Calculate difference between two dates

  • October 26, 2023
  • 8 replies
  • 536 views
  • Translate

Forum|alt.badge.img+10

Hello,

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([Datetime].[TotalMonths],[Form].[Repeating Section].[Current row].[FROM Date],[Form].[Repeating Section].[Current 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

Best answer by bsikes

I’d just go your initial route, and use the dateAdd function to add 1 day to your TO Date. 

dateDiff([Datetime].[TotalMonths],[Form].[Repeating Section].[Current row].[FROM Date],dateAdd("days",1,[Form].[Repeating Section].[Current row].[TO Date]))

View original
Did this topic help you find an answer to your question?

8 replies

bamaeric
Forum|alt.badge.img+13
  • Apprentice
  • 464 replies
  • October 26, 2023

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”:

          formatDate(dateAdd("months",12,[Form].[Start Date]),"MM/DD/YYYY")

If you just want the date to set a Date/Time control, you can remove the formatDate function.

Translate

Forum|alt.badge.img+10
  • Author
  • Scout
  • 85 replies
  • October 26, 2023

@bamaeric ,

Thanks for this! But what I am actually trying to do is grab a whole number of the months between 2 dates entered in.

So.

 

But I get 11 months...I’m still trying to figure out how to apply your response.

Translate

bamaeric
Forum|alt.badge.img+13
  • Apprentice
  • 464 replies
  • October 26, 2023

Hi @jpacheco,

Maybe try this to see if it gets you what you are looking for.

  1. Calculate the number of days between the dates -- Create a form variable of Integer type (named intDateDiffDays) and use this formula:

    dateDiff("TotalDays",[Form].[From Date],[Form].[To Date])
     
  2.  Next divide intDateDiffDays by 30 -- Create a form variable of decimal type (named decDaysToMonthsCalc) and use this formula:

    [Form].[intDateDiffDays]/30
     
  3. Finally round up the decDaysToMonthsCalc with 0 decimal points -- Create a form variable of decimal type (named decDaysDiffRounded) and use this formula:

    round([Form].[decDaysToMonthsCalc],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).

Translate

Forum|alt.badge.img+10
  • Author
  • Scout
  • 85 replies
  • October 26, 2023

@bamaeric ,

Thanks again for the quick response. I will attempt this.

Translate

Forum|alt.badge.img+10
  • Author
  • Scout
  • 85 replies
  • October 26, 2023

@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 [Form].[intDateDiffDays]/30?? I’m really confused...
 

 

Translate

Forum|alt.badge.img+10
  • Scout
  • 129 replies
  • Answer
  • October 26, 2023

I’d just go your initial route, and use the dateAdd function to add 1 day to your TO Date. 

dateDiff([Datetime].[TotalMonths],[Form].[Repeating Section].[Current row].[FROM Date],dateAdd("days",1,[Form].[Repeating Section].[Current row].[TO Date]))

Translate

Garrett
Forum|alt.badge.img+16
  • Scout
  • 904 replies
  • October 26, 2023

@bsikes solution is the simple and straight forward method. Add 1 day to the “TO Date”

Link to Form

 

Translate

almuhannadslc
Forum|alt.badge.img

@

  • Garrett the Link to Form is not working any more, can you resend it aging pls?

Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings