Print Page | Close Window

Calculate Age

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17133
Printed Date: 04 May 2024 at 4:54am


Topic: Calculate Age
Posted By: MW2011
Subject: Calculate Age
Date Posted: 26 Jul 2012 at 11:21am
I have a field on my report called birthday, I have a need to display the persons age on the report.

How does one go about that?

I already have a function in my application called calcAge which takes an input and returns the persons age.

Just dont know how to use it in my CR.

Thanks
MW2011



Replies:
Posted By: hilfy
Date Posted: 27 Jul 2012 at 11:53am
You can't use a function in an application to do this unless the function is in the database, in which case it can be called either in the select statement of a command or, if you're using just tables/views on your report, you can create a SQL Expression that will call the function.
 
If this is not in your database, you'll need to recreate the logic for it in a Crystal formula.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: Vermont Data
Date Posted: 30 Jul 2012 at 3:21am
I ran into this problem and created a variable called age today.  The way it works is to subtract Date_of_birth from Current_date.  This returns the number of days someone has lived.  Then I divide that by 365 (yep I ignore leap years) which give me a number with lots of decimals.  The next step if to kill those decimals, so round the number up and subtract 1. 
 
Here is the code:   Roundup((CurrentDate - {patient_current_demographics.date_of_birth}) / 365)-1


-------------
Joe Murray


Posted By: Vermont Data
Date Posted: 30 Jul 2012 at 3:23am
Opps I mean 365 not 360 in the formula

-------------
Joe Murray


Posted By: MW2011
Date Posted: 30 Jul 2012 at 11:59am
I ended up doing almost exactly like you did. Worked like a champ.
Someone told me to put the .25 because of leap year.

INT((CurrentDate - {AddTenants.Birthday}) / 365.25 )

MW2011



Print Page | Close Window