Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Calculating Years and Months

Avatar

Level 2

I want to have a field that will calculate out the years and months a person has been employed at my business.  I know the calculations for getting the years is:

if (HasValue(dob)) then

          var currDate_ = Date2Num(currDate.formattedValue, "MM/DD/YYYY")

          var dob_ = Date2Num(dob.formattedValue, "MM/DD/YYYY")

          var diff = currDate_ - dob_

          $.rawValue = Floor(diff / 365.25)

else

          $.rawValue = null

endif

I want to  find it put out so it says 5 years 3 months if that is possible, or something close to that.

0 Replies

Avatar

Level 10

var intYears = Floor(diff / 365.25)

var intMonths = Floor((diff - (intYears * 365.25)) / 30.4375)

var strOutput = Concat(intYears, " years, ", intMonths, " months")

xfa.host.messageBox(strOutput);