Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: Calculate Age Post Reply Post New Topic
Author Message
MW2011
Newbie
Newbie
Avatar

Joined: 26 Jun 2012
Location: United States
Online Status: Offline
Posts: 5
Quote MW2011 Replybullet Topic: Calculate Age
    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
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet 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
IP IP Logged
Vermont Data
Newbie
Newbie
Avatar

Joined: 30 Jul 2012
Location: United States
Online Status: Offline
Posts: 2
Quote Vermont Data Replybullet 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


Edited by Vermont Data - 30 Jul 2012 at 3:24am
Joe Murray
IP IP Logged
Vermont Data
Newbie
Newbie
Avatar

Joined: 30 Jul 2012
Location: United States
Online Status: Offline
Posts: 2
Quote Vermont Data Replybullet Posted: 30 Jul 2012 at 3:23am
Opps I mean 365 not 360 in the formula
Joe Murray
IP IP Logged
MW2011
Newbie
Newbie
Avatar

Joined: 26 Jun 2012
Location: United States
Online Status: Offline
Posts: 5
Quote MW2011 Replybullet 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
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.