Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2016 : Technical Questions
Message Icon Topic: Age calculation in Yrs, Mos and Days Post Reply Post New Topic
Author Message
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Topic: Age calculation in Yrs, Mos and Days
    Posted: 24 Sep 2015 at 11:03am
I need to calculate the age in years, months and days between DOB and a another date.
 
I've tried using the dateserial, datepart and datediff functions with no luck.
 
Any ideas?
IP IP Logged
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Posted: 24 Sep 2015 at 11:17am
I forgot to include my formula. I have some adjustments to make since some of the calculations are not accurate. Pretty close though...
 
If IsNull({Patients.DOB}) Then 'DOB Not Given' else
ToText(int(DateDiff('d',DateTimeValue({Patients.DOB}),{Episodes.DateColl})/365.25),0)+' Years '+
ToText(int(remainder(DateDiff('d',DateTimeValue({Patients.DOB}),{Episodes.DateColl}),365.25)/30),0)+' Months '+
If day({Episodes.DateColl}) < Day({Patients.DOB}) Then
ToText(day(dateserial(year({Patients.DOB}), Month({Patients.DOB})+1,1-1)) - Day({Patients.DOB}) + Day({Episodes.DateColl}),0) + ' days'
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1504
Quote kevlray Replybullet Posted: 24 Sep 2015 at 12:56pm
Ken Hamady has this formula on his web site.  I suspect it will work.  Go to  http://www.kenhamady.com/formulas/form06.shtml for more information.

WhileReadingRecords;
DateVar Birth:= {ages.Birth};   // Replace this with your field for Date Of Birth
DateVar Ann := {ages.DateAnn};  // Replace this with CurrentDate to get their age at runtime
                                                            //or a date field to get their age as of that date

//To increment the age of 'leap-year' babies on 2/28 instead of 3/1 (in non-leap years)

//if (Month(Ann) * 100) + Day (Ann) = 228
//and (Month(Ann+1) * 100) + Day (Ann+1) = 301
//and (Month(Birth) *100) + Day (Birth) =229
//then Year (Ann) - Year(Birth)
//else

if (Month(Ann) * 100) + Day (Ann) >=(Month(Birth) *100) + Day (Birth)
then Year (Ann) - Year(Birth)
else Year (Ann) - Year(Birth) -1

IP IP Logged
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Posted: 25 Sep 2015 at 8:12am
I have used he Ken Hamady formula. However, the age is calculated in yrs vs. yrs, mos and days.
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.