Is it a stored or auto-enter calculation? If so, it would only be triggered to evaluate when your DOB field is changed.
Yes, I know, and that's fine but the calculation is still off by months. I rather not have to trial and error the #days. Why is 6750 days not 18 years?
In your case, you also have some more glaring issues.
when you subtract a date from date, the result is? ... A date.
So you're trying to evaluate if a date result is less than an integer.
Also, dates in filemaker are stored as the number of days passed since zero.
EG, today, 4/4/2017 is 736423 when represented as a number.
So you need to convert to numbers BEFORE you try to evaluate the way you are doing things.
Easiest thing to do is explode this out into a Let() function like so:
cDate = GetAsNumber(Get(CurrentDate));
bDate = GetAsNumber(Members 4::DOB);
diff = cDate - bDate
if ( diff < 6750 ; "Y" ; "" )
You do not need to convert dates into numbers before you add or subtract them.
Yep! and there are so many ways to calculate "age" (search for it on this forum alone!)
Leap years notwithstanding, of course...
1 of 1 people found this helpful
Let ( [
BD = Members 4::DOB ;
now = Get ( CurrentDate ) ;
thisBD = Date ( Month ( BD ) ; Day ( BD ) ; Year ( now ) ) ;
passed = now < thisBD ;
age = Year ( now ) - Year ( BD ) - passed ;
Over18 = If ( age >= 18 ; "Y" )
Right. My math was off.
It looks like I must add days for leap years.
Is that correct?
no! the date calculations in FileMaker take care of that for you:
12/31/2016 + 1 = 1/1/2017
even leap years and days!!
Not sure where you got 6750, but that is way off. Even accounting for transposed digits, this 6570 doesn't account for leap years.
There are: 6,574 days from: 2017-04-04 until 18 years later: 2035-04-04.
- First: NEVER use "magic numbers" (hard-coded values) in calculations like 6750 (which was way off to begin with.)
- Second: Let FMP do the date math directly (avoid using days).
- Third: Take into account leap years if you must use "days" (as the above calculation I showed did).
HOPE THIS HELPS.
I had to make one correction: passed = now < thisBD changed to passed = now - thisBD .
And my preference is for Over18 = If ( age > 18 ; "Y" ) rather than Over18 = If ( age >= 18 ; "Y" )
No magic numbers in calculations or functions (hard-coded constants), please....
Actually, the "passed" line is supposed to produce a 1 for boolean true if now is less than thisBD. And, yes, you got the part about greater than. Hope it works well for you!