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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Age formula showing zero for a patient that is 10 months old

Status
Not open for further replies.

Garyjr123

MIS
Sep 14, 2010
139
US
I need to know how to show months as an age for this formula. It will calculate only in years and if I have a patient that is 10 months old the formula shows 0 as an age when I really want 10 months.

// birthday feb 29 and current year is leap year
if month({pat.birthdate})=2 and day({pat.birthdate})=29 and
day(date(year(CurrentDate),3,1)-1)=28
then
if date(year(CurrentDate),month({pat.birthdate}),day({pat.birthdate})- 1) > CurrentDate
then year(CurrentDate)-year({pat.birthdate})-1
else year(CurrentDate)-year({pat.birthdate})
else
// birthday not feb 29 or current year is a leap year
if date(year(CurrentDate),month({pat.birthdate}),day({pat.birthdate})) > CurrentDate
then year(CurrentDate)-year({pat.birthdate})-1
else year(CurrentDate)-year({pat.birthdate})
 
GaryJr123,

A slightly different approach, as I am unsure you need to concern yourself with the leap year for this calculation.

With my Person Table, I created the following and it works - only those persons less than 1 month old show as zero's.

Code:
IF DateDiff("yyyy",{Date of Birth},CurrentDate) = 0 THEN
DateDiff("m",{Date of Birth},CurrentDate)
ELSE
DateDiff("yyyy",{Date of Birth},CurrentDate)

Hope this helps!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
GaryJr123,

And if the approach works for you, the following will also identify which measure is being used. (I should have thought to include it in my prior posting)

Code:
IF DateDiff("yyyy",{CIF.Date of Birth},Date(2011,06,30)) = 0 THEN
    ToText(DateDiff("m",{CIF.Date of Birth},Date(2011,06,30)),0,"") & " Years"
ELSE
    ToText(DateDiff("yyyy",{CIF.Date of Birth},Date(2011,06,30)),0,"") & " Months"


Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top