INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Formula Help

How do I work out an exact age (in years & months) without CR rounding up? by phil2k
Posted: 5 Sep 03 (Edited 14 Jul 06)

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"

smilePhil
philip.richardson@sch.nhs.uk

Back to Business Objects: Crystal Reports 1 Formulas FAQ Index
Back to Business Objects: Crystal Reports 1 Formulas Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close