Skip 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.

Age from Date of Birth calculation doesn't work.

Featured Replies

Hi folks,

Is there anything wrong with the calculation below (swiped from Filemaker's own website if I remember correctly) correct?

It does give ages, but they're wrong & I can't work out what it's doing.

 

 

GetAsText ( Year ( Get ( CurrentDate ) )  - Year ( DateOfBirth ) - If ( Get ( CurrentDate ) <  Date ( Month ( DateOfBirth ) ; Day ( DateOfBirth ) ; Year ( Get ( CurrentDate ) ) ) ; 1 ; 0 ) ) & " Years, " & GetAsText ( Mod ( Month ( Get ( CurrentDate ) ) - Month ( DateOfBirth ) + 12 - If ( Day ( Get ( CurrentDate ) ) < Day ( DateOfBirth ) ; 1 ; 0 ) ; 12 ) ) & " Months, " & GetAsText ( Day ( Get ( CurrentDate ) ) - Day ( DateOfBirth )  + If ( Day ( Get ( CurrentDate ) )  ≥ Day ( DateOfBirth ); 0 ; If ( Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) < Day ( DateOfBirth ) ; Day ( DateOfBirth ) ; Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) ) ) ) & " Days"

 

Cheers!

Mike

  • Author

Thanks for that!

The rough information is useful for comparing achievement for kids - it doesn't have to be exact at all, a few days makes no difference, whereas a few months could.

Would I be better working out years & days? Or Years to decimal places? Is there a "best practice" solution for this?

 

Cheers,

MIke

Is there a "best practice" solution for this?
 
Not that I know of. It really depends on your purpose. For example, in pediatrics you normally calculate the age of infants in (whole) months where a month is calculated as something between 30 and 31 days.
 
If you still want a "pretty" years, months and days display, with no pretense at representing anything that could be meaningfully measured, try something like =
Let ( [
today = Get (CurrentDate) ;
elapsedMonths = 12 * ( Year ( today ) - Year ( DateOfBirth ) ) + Month ( today ) - Month ( DateOfBirth )
- ( Day ( today ) < Day ( DateOfBirth ) ) ;

temp = Date ( Month ( DateOfBirth ) + elapsedMonths ; Day ( DateOfBirth ) ; Year ( DateOfBirth ) ) ;
limit = Date ( Month ( DateOfBirth ) + elapsedMonths + 1 ; 0 ; Year ( DateOfBirth ) ) ;
bDay = Min ( temp ; limit ) ;

y = Div ( elapsedMonths ; 12 ) ;
m = Mod ( elapsedMonths ; 12 ) ;
d = today - bDay
] ;
y & " Years, " & m & " Months, " & d & " Days"
)
  • Author

Many thanks for this.

It seems to be months out, e.g.

 

DoB 27 Sep 1999 = 14 years, 0 months 16 days.

21 Jun 2000 = 13 yr, 3 months, 22 days.

 

The odd day here & there isn't an issue, but months are significant! Any idea what's happening? - does FM take today's date automatically from the system, or do I need to set it up somewhere?

DoB 27 Sep 1999 = 14 years, 0 months 16 days.

21 Jun 2000 = 13 yr, 3 months, 22 days.

 

I am not sure how you got those results. I am getting "14 Years, 9 Months, 20 Days" for the former and  "14 Years, 0 Months, 26 Days" for the latter (with current date being July 17, 2014).

 

 

does FM take today's date automatically from the system

 

Yes, it does. Make sure you are using an unstored calculation field, with the result type set to Text.

Note that your results can be reproduced if today is assumed to be October 13, 2013. Perhaps your system date is wrong? That could also explain why you had problems with the FMI calc - which although very poorly written is still essentially "correct" (at least upon superficial examination).

  • Author

Changing the field type sorted it.

I'm not sure which change it was, but mistake candidates were:

  • "don't replace existing contents"
  • & type as number
  • I don't think I had it as a calculation field either!!

Other than that, a masterful display of competence on my part!!

 

Many thanks for your help :-)

Mike


Ah, I reckon Oct 2013 must be around about when I added the field - it must have just stayed as that because I didn't allow FM to update the field contents.

 

Thanks!

Mike

What you had was a text field, with the Auto-enter options set. That field will not update unless you do something to make it update.

 

From the Manage Database dialog, you field type needs to be "Calculation". Result ( set in the calculation dialog ) needs to be text. Storage options set to 'unstored'.

 

  • "don't replace existing contents"
  • & type as number
  • I don't think I had it as a calculation field either!!

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

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.