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

Calculating Age with decimals 2

Status
Not open for further replies.

ggies07

Technical User
Jun 27, 2013
40
0
0
US
Hello,

I got great tips from this thread referenced below, but it only gave me whole numbers and I can't seem to find where in the formula to insert coding that makes it turn into decimals instead of whole numbers. I need to add 3 months to the birth date, but still have the new number come out with the Age + whatever months are left over into a decimal. Any thoughts? Thanks!

Here is the formula I used:

WhileReadingRecords;
DateVar Birth:= date({StsSt.StsSt_Birthdate});
DateVar Ann := date(DateAdd ("m",3 ,CurrentDate));
if (Month(Ann) * 100) + Day (Ann) >=(Month(Birth) *100) + Day (Birth)
then Year (Ann) - Year(Birth)
else Year (Ann) - Year(Birth) -1

thread767-1534223
 
ggies07,

You are not going to ever get decimals, as "Years" are always whole numbers (The year of June 15 2013 is 2013, not "2013.5" (or something close)). I think what you would likely need to do is all your math with "date 1 minus date 2" (which should be in "Days" as I recall) then take this divided by 365 (or 366 or perhaps 365.25 (1 extra every 4 years) -- number of days in a year) -- then you will be able to have decimals, I think.

I don't have time just now to look into the specific formula development for you, but perhaps this is enough to get you going in the right direction.

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."
 
Thanks Mike. I'll play around with it. That makes sense about using years. That formula gave me a great start by getting the future age my boss wanted, but now I have to get it even more detailed. She did not like that it was rounded to a whole number.....Whenever you get the time, any help in getting the formula to do this would be great. Thanks!
 
Hey Mike,

I tried this: DateDiff ("d",{StsSt.StsSt_Birthdate} , date(08/26/2013)) / 365.25

That formula gave me 107.60 for one of the students, but his future age should be 6.1, he's 5 years and 10 months right now. So while what I did got me a number in decimal, it's still off. Do I need to add something to it or is this not in the right direction?

Thanks!
 
To be honest I am not sure I understand why you are trying to do it, but from what I readi it seems you are trying to work out the age (in years) of the person in 3 months time. Assuming I have interpreted the requirements correctly, try:

Code:
DateDiff("m", {StsSt.StsSt_Birthdate}, (DateAdd("m", 3, CurrentDate)))/12

Using the example you quote in your last post it returns 6.1. If he is 5 yrs and 10 months now, he is 70 months old. In 3 months he will be 73 months old (well actualy 6.0833333 years).

Is this what you are trying to do?

Cheers
Pete
 
Or, to simplify it even further:

Code:
(DateDiff("m", {StsSt.StsSt_Birthdate}, CurrentDate) + 3) / 12

Pete
 
Hi Pete,

I plugged your formula in and it works, thanks! Much appreciated. I couldn't figure out how to get there, but I understand it after looking at it.

I'm having to get this future age because the admissions director uses it in May to do placement for the next school year, thus having to add 3 months to their age.
 
Glad it helped.

If it is always the same date as at which the director needs to know the age you could hard code that date, eg for Aug 31 each year the formula would be:

Code:
DateDiff("m", {StsSt.StsSt_Birthdate}, Date(Year(CurrentDate),8,31) / 12

Or, you could use a parameter to enter a specific date:

Code:
DateDiff("m", {StsSt.StsSt_Birthdate}, {?EffectiveDate}) / 12

Cheers
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top