Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I work out an exact age (in years & months) without CR rounding up?

Formula Help

How do I work out an exact age (in years & months) without CR rounding up?

by  phil2k  Posted    (Edited  )
This formula converts the numbers to text so that the decimal places can be trimmed of without being rounded up. It works perfectly for people up to 99 years 11 months of age (could be modified to go higher)

numbervar var_totalmonths := DateDiff "m",{table.Date of Birth},{table.Target Date});
stringvar var_remainingmonths := Totext(var_totalmonths mod 12);
stringvar var_years := ToText(var_totalmonths/12);
stringvar var_yearstrimmed := If Length (var_years) = 5 Then (Left(var_years,2)) Else (Left(var_years,1));
stringvar var_remainingmonthstrimmed := If Length (var_remainingmonths) = 5 Then (Left(var_remainingmonths,2)) Else (Left(var_remainingmonths,1));

Cstr(var_yearstrimmed) + "yrs" + Cstr(var_remainingmonthstrimmed) + "mths"

:)Phil
[color blue]philip.richardson@sch.nhs.uk[/color]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top