Jump to content
Salesforce and other SMB Solutions are coming soon. ×

Age calculation for a perfect newbie


Henri
 Share

Recommended Posts

Hi :)

 

I'm sure this question was asked and answered before but I couldn't find it in my quick search.

 

I'm working for a non-profit organization and I'm not a programmer/scripter/etc.

 

I did a FileMaker database to store in our clients files. Everything works fine! Except for one thing: I can't calculate the actual age with date of birth.

 

I found where to put in some scripts but couldn't find the "Actual date"... I've created a "Date of birth" field (Date type) wich I called (in french language) "Date de Naissance". Can someone please explain me or type me the code I can put in the calculation field to have the age calculated and refreshed each time we open the file?

 

Maybe it's good for you to know that we're using the french version (we're in Montreal) of FMP 8.0. For now it's the 30-days version, we'll buy the full version when the database will be complete.

 

Thanks a lot! Any help will be really appreciated!

 

Henri

Link to comment
Share on other sites

Hi Henri,

 

You haven't said how you want it displayed .. if you just want years, you can use this as calculation - no script needed:

 

Let ( [

now = Get ( CurrentDate ) ;

thisBD = Date ( Month ( DOB ) ; Day ( DOB ) ; Year ( now ) ) ;

passed = now > thisBD

] ;

Year ( now ) - Year ( DOB ) - passed

)

 

Result should be number (unstored).

 

LaRetta smiley-laughing

Link to comment
Share on other sites

Thank you so much LaRetta! Everything is working fine now!

 

I made a little correction to your code (a simple error, see below in red) for it to calculate correctly the age.

 

Have fun and thanks again!

Henri

 

 

Hi Henri,

 

You haven't said how you want it displayed .. if you just want years, you can use this as calculation - no script needed:

 

Let ( [

now = Get ( CurrentDate ) ;

thisBD = Date ( Month ( DOB ) ; Day ( DOB ) ; Year ( now ) ) ;

passed = now

] ;

Year ( now ) - Year ( DOB ) - passed

)

 

Result should be number (unstored).

 

LaRetta smiley-laughing

Link to comment
Share on other sites

Hmmm, you might want to take another look. Let's use an example:

 

Someone was born on 7/31/2000. On today (7/31/2006), they will be 6. Yesterday they would still be 5. Try my calc again and then yours. smiley-smile

Link to comment
Share on other sites

I was in error as to the context ... passed should be called notPassed. What happens is that 2006-2000 = 6. But the person won't be six until 7/31/2006. so 'passed' says that if today is greater than their birthdate this year it means their birthday hasn't passed. I just called it passed because it was a boolean test whether it had passed or not.

 

If their birthday hasn't been passed then we need to subtract one year from their age. I should have made passed something which specifies what it is doing. Thank you, Henri, for reminding me of the importance of naming variables. I will be more careful in the future. smiley-laughing

Link to comment
Share on other sites

Could you please tell me which formula to use if i need the age in months? I am to create a database for a lab in which experiments on rats are done, and thus we need to have age in months to conveniently follow the progression. Thanks.

Link to comment
Share on other sites

1. Please do not double-post.

 

2. Age in months is always problematic, because month length in days varies. Some compromise is required. For example, you can try:

 

12 * ( Year ( EndDate ) - Year ( StartDate ) )

+ Month ( EndDate ) - Month ( StartDate )

- ( Day ( EndDate )

 

This considers a month as completed when it reaches the starting date's day-of-month, so from Feb 28 to Mar 28 is a full month, but from Jan 31 to Feb 28 is not.

Link to comment
Share on other sites

  • 2 weeks later...

Do you have calculations for Year and Month that don't involve the Get(Current Date) function. I need to calculate year and month values based on the difference between test dates and date of birth. I am getting the incorrect years or months coming up depending on if the month is the same and the day value is before or after the DOB. Fields are as follows:

CMVAgeYrs = Case(not IsEmpty(CMVDOB); Year(CMVTestDate) - Year(CMVDOB)) - Case(Month(CMVTestDate)

CMVAgeMos = Case(not IsEmpty(CMVDOB); Mod(12 + Month(CMVTestDate) - Month(CMVDOB) - Case(Day(CMVTestDate)

Both are unstored and number values. If the test DOB is empty, I don't want a calc as that means that the test was not done.

Any help with this. I keep seeing the Get(Current Date) function used but can't change similar formula to work for me. Thanks Nanette

Link to comment
Share on other sites

Any calculation that uses Get(CurrentDate) can be modified by replacing Get(CurrentDate) with the name of the field that holds the ending date of the period (I think that would be CMVTestDate in your case). The calculation then can be stored - if so desired.

Link to comment
Share on other sites

I thought that, too and tried it. But, I keep getting error messages that I am missing or have too few parameters. I took apart the calculation and make sure all the right () were there and it still won't run, same error message. Not sure what the issues is as I am only removing the "Get(Current Date)".

What could be wrong with the calculation that I was using in the first place? Anyone?

Thanks

Nanette

Link to comment
Share on other sites

There are many things wrong with the calculations that you quoted. Instead of going into details, why don't you tell us what are you trying to calculate?

Link to comment
Share on other sites

  • 4 years later...

I have looked at these posts, and various factors can cause false ages. So, I decided to work under the premise of first looking at the DOB (date of birth) as if it was in the same year as the current year. This will identify if the birthdate is today, in the past within this year, or in the future within this year. Then, based on whether it is =, , it will subtract the birth year from the current year (or subtract an extra year if the birth date this year falls after the current date this year). I wrote it out longhand so you can see three scenarios.

:)

 

Case (

DayOfYear ( Date ( Month (DOB); Day (DOB); Year ( Get (CurrentDate )))) = DayOfYear ( Date ( Month ( Get ( CurrentDate )); Day (Get ( CurrentDate )); Year (Get ( CurrentDate )))); Year ( Get ( CurrentDate ) ) - Year ( DOB );

DayOfYear ( Date ( Month (DOB); Day (DOB); Year ( Get (CurrentDate ))))

DayOfYear ( Date ( Month (DOB); Day (DOB); Year ( Get (CurrentDate )))) > DayOfYear ( Date ( Month ( Get ( CurrentDate )); Day (Get ( CurrentDate )); Year (Get ( CurrentDate )))); Year ( Get ( CurrentDate ) ) - Year ( DOB ) - 1)

Link to comment
Share on other sites

 Share



×
×
  • Create New...

Important Information

Terms of Use