Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

calculating age in calculation field

Featured Replies

Field 1: Date of birth

Field 2: Current date or entered date

Field 3: Current age (calculation field)

Question: Specifically how do I set up the calculation field for field 3? I have tried to figure this out by searching the online help and the post histories for calculating age. Sorry if this has been covered elsewhere.

Thanks.

Doug Lazenby

Do you need anything beyond the number of full years completed? Assuming you've got BirthDate as one Date-type field:

If

(DayofYear(BirthDate)=<DayofYear(Get(CurrentDate));

Year(CurrentDate)-Year(BirthDate);

(Year(CurrentDate)-Year(BirthDate))-1)

I haven't used it, but check and see whether the logic makes sense to you.

There seem to be plenty of age calculations floating around, but you must be careful its reliable for all situations. This one seems to be bullet-proof.

Year(Get ( CurrentDate )) - Year(DOB) - (Get ( CurrentDate ) < Date(Month(DOB); Day(DOB);Year(Get ( CurrentDate ))))

Where DOB equals Date of Birth, result is an unstored number.

This was published by DataIsland Software. It looks like what you are looking for.

// This is a Custom Function version of calculations provided in "Advanced FileMaker Pro 5.5" by Chris Moyer and Bob Bowers. This formula differs slightly from the ones in the book which do not account for leap years.

Let ( leapFactor = If ( Mod ( Year ( theDate ) ; 4 ) = 0 ; 1 ; 0 );

Case (

// Age in years

format = 1 ; Year ( theDate ) - Year ( birthDate ) - ( ( DayOfYear ( theDate ) - leapFactor ) < DayOfYear ( birthDate ) );

// Age in years and days

format = 2 ; Year ( theDate ) - Year ( birthDate ) - ( ( DayOfYear ( theDate ) - leapFactor ) < DayOfYear ( birthDate ) ) & " years and " & Case (

( DayOfYear ( theDate ) - leapFactor ) ? DayOfYear ( birthDate ) ; DayOfYear ( theDate ) - leapFactor - DayOfYear ( birthDate ) ;

DayOfYear ( theDate ) + ( DayOfYear ( Date ( 12 ; 31 ; Year ( theDate ) ) - DayOfYear ( birthDate ) - leapFactor ) ) ) & " days" ;

// Age in years, months and days

Format = 3 ; Year ( theDate ) - Year ( birthDate ) - ( ( DayOfYear ( theDate ) - leapFactor ) < DayOfYear ( birthDate ) ) & " years and " & Mod ( Month ( theDate ) - Month ( birthDate ) + 12 - (Day ( theDate ) < Day ( birthDate ) ) ; 12 ) & " months, and " & (theDate - Date ( Month ( theDate ) - (Day ( theDate ) < Day ( birthDate ) ) ; Day ( birthDate ) ; Year ( theDate ) ) ) & " days"

)

)

  • Author

I appreciate everyone's thoughtful replies. I think I made it too complicated. I just need the age in years. I fooled around with the calculation field and this is what I did which seems to get the job done:

In the calculation dialog box I typed:

(CurrentDate-patientmaindata::PatientDOB)/365.

I then formatted the number as a decimal with no numbers behind the decimal point to give me a whole number.

It is an unstored value--I don't know how to make it stored, or whether that is more desirable-- I do wish I could store it.

This should also work for leap years I think.

Doug

Why do you want to store it? The calculation becomes static and won't show the "current" age any longer, if it is stored (unless one of the involved values changes for a record).

try this. If the DOB field is left blank for some reason you won't get the "?" in the age field. This also takes into account the leapyear factor by using 365.25 vs. 365. Good luck!

Case(IsEmpty(DOB),"",Truncate((Report Date-DOB)/365.25,0))

Messing around with the quarter days isn't reliable. Here's what I use

Year(Get(CurrentDate)) - Year(DOB) - If(Get(CurrentDate) < Date(Month(DOB); Day(DOB); Year(Get(CurrentDate))); 1; 0)

In English this says: 'Subtract the year of birth from this year, and if they haven't had their birthday yet this year, subtract 1 more from that.'

The internal date stuff takes care of all the leap years.

Dan

Why bother with the If statement, a boolean expression will always return a 0 or a 1.

Year(Get ( CurrentDate )) - Year(DOB) - (Get ( CurrentDate ) < Date(Month(DOB); Day(DOB);Year(Get ( CurrentDate ))))

Good point. I guess I sacrificed a few electrons for the sake of clarity so I could remember what I was doing when I looked back on it later. But yours acrually does the job more efficiently.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.