today = Get ( CurrentDate );
dob = DateOfBirth
today > dob and IsEmpty(dob) ≠ 1;
Year(today) - Year(dob) - If(today < Date(Month(dob);
Day(dob); Year(today)); 1; 0);
--> Remember to define calc as a number and we do not evaluate if all referenced fields are empty (tickbox)
--->There might be more savvy ways, we have had this calc in our db for years!
1 of 1 people found this helpful
... and make the calculation unstored.
Thanks much! Also found this in case you need an alternative.
GetAsText ( Year ( Get ( CurrentDate ) ) - Year ( Student Birth Date ) - If ( Get ( CurrentDate ) < Date ( Month ( Student Birth Date ) ; Day ( Student Birth Date ) ; Year ( Get ( CurrentDate ) ) ) ; 1 ; 0 ) )
There's always the even simpler:
Int((Get(CurrentDate) - Date of Birth) / 365.25)
If you really need two digits you can use the RIGHT function:
Right ( "00" & Year ( get ( currentDate ) - Date of Birth ) ; 2 )
This will result in age: 01
I'm afraid this calculation will not always give the correct answer on someone's birthday. E.g. with your calculation a DOB = 1/1/2001 will result in age=10, not 11, if today is 1/1/2012.
The reason is: (birth) dates and ages are discrete values, not fractions. Dividing by 365.25 doesn't account correctly for leap years. A year is either a leap year, or it isn't. Years on the calendar do not have 365.25 days. Of course, astronomically they do (approximately), but that's not practical for earthbound use. It's why we have leap years in the first place.
The leap day itself is a discrete, 'sudden' shift.
But what about the centarians out there!?
Hail Caesar! Oh, centarian, not centaurian.
It's interesting how challenges like these illustrate the assumptions we make -- such as 2 digits for the age, and a year being 365.25 days.