1 Reply Latest reply on Mar 19, 2014 4:21 PM by philmodjunk

    Calculating time (in Months) between two dates

    ZiteMedia

      Title

      Calculating time (in Months) between two dates

      Post

           Hello,

           I'm trying to figure out the correct formula which should give the number of months that remain between "today" (or CurrentDate?) and a date in the future (from another field  "contract_end_bup").

           Clearly, this formula     "Month ( contract_end_bup ) - Month ( Get ( CurrentDate ) )"      is not the way to go, as it only gives me the correct result as long as the two dates are within the same year.

           Would be great if someone could help me out as i'm really stuck on this one...  :-/

           Much appreciated!

        • 1. Re: Calculating time (in Months) between two dates
          philmodjunk

               What is your definition of "month", sometimes it's sufficient to subtract the two dates--which produces the elapsed time in days and then divide by 30.

               ( Get ( CurrentDate ) - contract_end_bup ) / 30

               Other times, that will not meet the needs of your system.

               Let ( [ M1 = Month ( contract_end_bup ) ;
                         Y1 = Year ( contract_end_bup ) ;
                         M2 = Month ( Get ( CurrentDate ) ) ;
                         Y2 = Year ( Get ( CurrentDate ) )
                       ];
                         12 * ( Y2 - Y1 ) +  M2 - M1
                      ) // Let