Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 8096 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies
Posted

Does anyone know of the simplest way to calculate age in years? I have a field called "Birthday." Year(Today-Birthday) does not work... I have longer, complicated solutions, but am I missing some simple function?

I would be happy to know of any web sites or books that archive common calculation solutions... or maybe this is the place!

Thanks, Chuck

Posted

Almost got it Chuck, try

Year(Today)-Year(Birthday)

with the result being a number. Note that this may not give the correct result if the Birthday is after the Today date as it is only looking at the year component of the dates.

You could also try

(Today-Birthday)/365.25

with the result as a number. This will give a more accurate age for the individual.

Keep in mind the problems inherent in using the Today function (recalculation time, refreshing function), especially on large databases.

  • 3 weeks later...
Posted

I had a similiar problem with my student database and successfully implemented a solution I located on the www:

NumToText(Year(Today) -Year(DOB) - Case(Today<Date(Month(DOB), Day(DOB),

Year(Today)), 1, 0)) &

  • 3 weeks later...
Posted

Here's yet another solution.

You need three fields

Today's Date

Birth Date

Age

Use the formula

Age=(Today's Date-Birth Date)/365

This calculation gives you the number of days between today's date and the birth date. So when you divide it by 365 you get the number of years. There is a drawback to this calculation as well. It does not take into account for leap years.

------------------

Ryan

[email protected]

  • 1 month later...
Posted

This will give you everything. Create four fields. 1.Date of Birth Field.

2. Age Year

3 Age Month

4. Age Day

The last three are calculation fields that will give you your age by year, month and day by copying in the calculations below.

CALCULATION FOR YEAR:

Year(Today) - Year(DOB 1) - If(Today< Date(Month(DOB 1),Day(DOB 1),Year(Today)),1,0)

CALCULATION FOR MONTH:

Mod(Month(Today) - Month(DOB 1) + 12 - If(Day(Today) < Day(DOB 1),1,0),12)

CALCULAITON FOR DAY

Day(Today) - Day(DOB 1) + If(Day(Today) >=

Day(DOB 1),0,If(Day(Today- Day(Today)) <

Day(DOB 1),Day(DOB 1),Day(Today- Day(Today))))

If you only want the year, place only that field on your layout. Good Luck

------------------

Bob Sherman

[email protected]

  • 2 weeks later...
Posted

Why don't people use the Status (CurrentDate) and Status(CurrentTime) instead of the Today function?

  • 1 year later...
  • Newbies
Posted

This solution builds on the one of birdman, above. Thanks for the tip. This one goes one step further by limiting the result to the first two digits of the calculation. It works fine as long as the person is not over 100 years old.

You only have to create a "Birthday" field (as a "date" type) and an age calculation field using this formula:

left ((Today - Birthday) / 365.25, 2)

To increase the calculation to include ages over 100, do this:

left ((Today - Birthday) / 365.25, 3)

In this case, people less than 100 will look something like "45.", while those over will look fine.

Posted

I tend to dislike any date calculation that uses hard-coded values like 365.25 because by design they won't be accurate. With thought, ways can be discovered to do the task that involve only FMP's built-in date functions.

Year(Status(CurrentDate)) - Year(birthday) -

Case(Month(Status(CurrentDate)) < Month(birthday), 1,

Month(Status(CurrentDate)) = Month(birthday),

If(Day(Status(CurrentDate)) < Day(birthday), 1, 0),

0)

It could even be extended to working out the age down to birth time as well for extra accuracy: I'll leave that as an exercise.

  • 5 months later...
Posted

Bob,

I tried this calculation using "DOS" which is my Date of Service in place of current date and it didn't work. I get an error message that "DOS" is not a valid status flag. Any ideas?

What I am trying to do is just what you did but rather than using the current date off my computer, I want to use a date I select because the service may have been done a few days ago or even 5 years ago. Thanks, Carlo

Posted

I've been using one like this for a long time now working on medical records databases:

Enter the actual date of birth in

field(date): [color:"green"] person.ageDateOfBirthEntry

Calculation(number) field: [color:"red"]person.AgeCurrent =

Truncate( (Status(CurrentDate) - [color:"green"]person.ageDateOfBirthEntry)/365, 0)

If you want to capture the person's age at a particular point in time/event, then change the "Status(CurrentDate)" to the date of the event. Otherwise, the persons age will always reflect their age at the current moment in time.

Posted

I tried this calculation using "DOS" which is my Date of Service in place of current date and it didn't work. I get an error message that "DOS" is not a valid status flag. Any ideas?

You need to replace all of "Status(CurrentDate)" with "DOS". Do NOT write "Status(DOS)". Here is my recommended age calculation:

Year(Status(CurrentDate)) - Year(Birthdate) - (Status(CurrentDate) < Date(Month(Birthdate), Day(Birthdate), Year(Status(CurrentDate))))

which for you would become:

Year(DOS) - Year(Birthdate) - (DOS < Date(Month(Birthdate), Day(Birthdate), Year(DOS)))

HTH.

  • 4 weeks later...
Posted

The beauty of FM is that I simply copied the text that Kennedy posted into my Age field definition (after creating a Birthdate field). I had an Age field fully functional in less than 30 seconds. I appreciate the ease of FM now that I am taking C++ and Access in college.

Ken

This topic is 8096 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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