1 2 Previous Next 16 Replies Latest reply on Mar 9, 2016 6:41 PM by Vaughan

# calculating age?

I have a series of date of birth fields: dob1, dob2 etc... and i would like to display a field next to each that displays the age in years.  The dob field will be entered and displayed like this: 1/1/2016

i have seen this calculation but i have no idea what to do with.  i assume age is a field name and the Birthdate is the dob field i have already?

age = Year ( Get ( CurrentDate ) ) - Year ( Birthdate ) - ( Get ( CurrentDate ) < Date ( Month ( Birthdate ) ; Day ( Birthdate ) ; Year ( Get ( CurrentDate ) ) ) )

• ###### 1. Re: calculating age?

This custom function should work for you.

Let ( [

todaysDate = Get ( CurrentDate ) ;

DOB = GetAsDate ( BirthDate )

] ;

Year ( todaysDate ) -

Year ( DOB ) -

(

todaysDate < Date (

Month ( DOB ) ;

Day ( DOB ) ;

Year ( todaysDate )

)

)

)

It's largely the same thing, but by using the Let statement, you avoid forcing FileMaker to recalculate the current date three times (which is what the calc you have does).

And yes, in your original calculation, "age" would be either a field or a variable definition. It's the result of the calculation.

• ###### 2. Re: calculating age?

thanks sp much for the answer, but i am unclear which field is what.  sorry!  so i have a field called dob1, dob2 and so on... in your formula would the dob be this field and what is the BirthDate field?

• ###### 3. Re: calculating age?

Good afternoon bobinaustin,

I hope your day is going well. I may be missing something, but if both fields are configured as Date type it seems like you should be able to use a calculation like this:

Year ( Get (CurrentDate) - DOB_Field)

Hope this helps. Have a great day!

God bless,

Bill

EDIT: You would set the field displaying years in age as a Calculation type, enter the calculation above using your DOB field, and set the Calculation result is: Number

• ###### 4. Re: calculating age?

Hi Bill

Thanks for the suggestion.  It seems too good to be true!  When i try your calculation it simply returns the current year.  I am looking for an age.

• ###### 5. Re: calculating age?

Hey bobinaustin,

Take a look at the attached sample file (it's rough).

• ###### 6. Re: calculating age?

Hey bobinaustin,

Sorry, I made a mistake in my calculation. It should be as follows:

Year (Get (CurrentDate) - DOB_Field) - 1

See attached file.

• ###### 7. Re: calculating age?

It's not a field. It's a calculation. The calculation goes in the calculation dialog for the field.

See attached.

• ###### 8. Re: calculating age?

Won't work. There are two cases:

1) The person's birthday has come this year.

2) The person's birthday has not come yet this year.

Your first calc handles case 1. Your second handles case 2. You need a calc that handles both.

• ###### 9. Re: calculating age?

Good afternoon Mike,

I hope your day is going well. As I said, I may be missing something, but when I test the calculation it seems to work correctly. I tested using a birth date with a month and day earlier that the current date and with one later...it seemed to work for me.

God bless,

Bill

• ###### 10. Re: calculating age?

Age from dob

Chris Cain

Extensitech

• ###### 11. Re: calculating age?

I was born in 1966. As of right now I'm 49 years old because my birthday hasn't come yet this year. However, when my birthday rolls around I will turn 50. The year hasn't changed; it's still 2016.

So if I subtract 2016-1966, I get 50. That's wrong right now, because I haven't turned 50 this year. But if I subtract 2016-1966 minus one I get 49, even after my birthday has passed, which is also wrong.

It doesn't work unless you account for whether the person has passed his birthday or not in the current year.

• ###### 12. Re: calculating age?

Hey Mike,

Okay, I did some testing with the test_01.fmp12 file I posted using the year of your birth (1966) and the current date's month and day. The answer I get is 50 years in age. If I keep the same year (1966), but enter the month and day as March 10 - the day after the current date's month and day - I get 49 years in age. What am I missing?

...I think I may have confused myself.

God bless,

Bill

• ###### 13. Re: calculating age?

Because I'm both 49 and 50 this ... same ... year. I'm not 50 yet.

Besides, why would my age go down?

• ###### 14. Re: calculating age?

Hey Mike,

I'm not being intentionally thick, you're obviously a much more experienced FileMaker developer than I am, but I must be completely missing your point. My thought was that if the month and day of your birth date was on or before the current date's month and day the calculation should show your age as 1 year more than if the month and day of your birth date came after the current date's month and day. Are you saying that it should be different?

God bless,

Bill

1 2 Previous Next