Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Calculating Age from Two Dates

Posted on 2006-07-10
Medium Priority
991 Views
Very new, as in 2  weeks, to Filemaker and trying to clean up anothers mess. I need to perform a variety of date calculations, which all boil down to subtracting two dates from each other and reconstituting the difference back into years & months. Thus subtracting 1/1/2000 from 7/1/2006 would give me something on the order of "6 years 6 months" (or 6.6 which would be acceptable). I would not want the resulting answer to exceed two digits for years and 2 digits for months, so a resulting calculation of 10.11 (ten years eleven months) would be acceptable, but 10.111111111 (ten years ad nausem) would not.

Thanks,
Bob
0
Question by:Bob_Gardner
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5
• 5

LVL 3

Expert Comment

ID: 17078920
The main problem with date math are extreme samples. For example, how would you like to round the incomplete months? Could you please tell how the formula you're looking for must behave in the following cases?

March 1, 2006..March 20, 2006 = 0.1? or 0.0?

March 30, 2006..Apr 30, 2006 = 0.1? or 0.0?
0

Author Comment

ID: 17079419
Edoshin
Thanks for the response. Incomplete months would be 0.

March 1, 2006..March 20, 2006 = 0.1? or 0.0? -> Would be 0.0

March 30, 2006..Apr 30, 2006 = 0.1? or 0.0? -> would most be 0.1, given 30 days in April and 31 in March.
0

LVL 3

Expert Comment

ID: 17079623
I forgot yet another case: Apr 30...May 30. Should it be 0.0, because the end of March isn't reached yet or 0.1, because it seems natural. Anyway, here's a sketch of the formula:

Let( [
date 2 = <your other field>;
month 1 = Month( date 1 ); day 1 = Day( date 1 ); year 1 = Year( date 1 );
month 2 = Month( date 2 ); day 2 = Day( date 2 ); year 2 = Year( date 2 );
incomplete month =
date 2 < If( Month( Date( month 2; day 1; year 2 ) ) = month 2;
Date( month 2; day 1; year 2 );
Date( month 2 + 1; 0; year 2 ) );
number of months =
( year 2 - year 1 ) * 12 + ( month 2 - month 1 ) - Case( incomplete month; 1 ) ];

Div( number of months; 12 ) & "." & Mod( number of months; 12 ) )

It calculates Apr 30..May 30 as "0.1"
0

Author Comment

ID: 17083207
Edoshin
I think there is a problem brought on by the fact that I failed to specify that the FM version being used is 6.04. That said, unless there is a typo in your formula, there is no "Let" or "Div" functions. I have included my rendition of your formula, which I was going to test, but can not get FM to accept it in the calculation portion of the field definition.

Let([
date1=Today;
date2=Date of Birth;
month1=Month( date1); day1=Day(date1); year1=Year(date1);
month2=Month(date2); day2=Day(date2); year2=Year(date2);
incomplete month = date2< If(Month(Date(month2; day1; year2))=month2;
Date(month2; day1; year2);
Date(month2 + 1; 0; year2));
number of months=(year2-year1) * 12 + (month2-month1)-Case(incomplete month; 1)];
Div(number of months; 12) & "." & Mod(number of months; 12))
0

LVL 3

Accepted Solution

Edoshin earned 2000 total points
ID: 17087815
Then the formula will be way longer and hardly readable :)

Int( ( ( Year( Today) - Year( Date of Birth ) ) * 12
+ ( Month( Today) - Month( Date of Birth ) )
- ( Today< If( Month( Date( Month( Today), Day( Date of Birth ), Year( Today) ) ) = Month( Today),
Date( Month( Today), Day( Date of Birth ), Year( Today) ),
Date( Month( Today) + 1, 0, Year( Today) ) ) ) ) / 12 )
& "."
& Mod( ( ( Year( Today) - Year( Date of Birth ) ) * 12
+ ( Month( Today) - Month( Date of Birth ) )
- ( Today< If( Month( Date( Month( Today), Day( Date of Birth ), Year( Today) ) ) = Month( Today),
Date( Month( Today), Day( Date of Birth ), Year( Today) ),
Date( Month( Today) + 1, 0, Year( Today) ) ) ) ), 12 )

Also, I see you use the Today function, which is typically avoided by FileMaker developers and has been completely removed in v7. It can be used, but under quite specific circumstances and since you work with FileMaker for short time, you probably don't know its specifics. Would you like me to explain what's wrong with it?
0

Author Comment

ID: 17088456
Edoshin ,

Thanks - I'll try you latest code in the morning - I'm in Seattle and its a little after midnight. By the way, after I posted that bit, and before I got your latest response, I read a short note on the 'today' problem, with the recommendation that Status(CurrentDate) be used. I am now using that - I hope that is correct. I understood that 'today' is very, very slow - amonst other issues. As an aside, I do NOT like FM (at least not what I have seen so far) and being a child at it is very frustrating. More later.
Bob
PS If this works out - I'm upping the points to 500. I sincerely appreciate your assistance.
0

Author Comment

ID: 17096876
Edoshin,
Hmmm .. there seems to be a slight problem. I had the field define as a number, which resulted in 18.5.6, and then when I changed the field to text, it resulted in 18.4111 (not using the same set of dates in both tests). I am not sure what problem may be causing these results. Any ideas?
0

LVL 3

Expert Comment

ID: 17096932
Something is wrong with the formula. Try this sample file: http://www.mytempdir.com/800622
0

Author Comment

ID: 17100234
Edoshin,

That worked! Great! Thanks lots.
Bob
0

LVL 3

Expert Comment

ID: 17101575
You're welcome :) Maybe you'll eventually like FileMaker :)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem: You have a hosted FileMaker database and users are tired of having to use Open Remote or Open Recent to access the database. They say, "can't you just give us something to double-click on rather than have to go through those dialogs?" Anâ€¦
Having just upgraded from Filemaker 11 to Filemaker 12 over the weekend, we thought we would add some tips for others making the same move.  In general, our installation went without incident. Please note that this is not a replacement for Chapter 5â€¦
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signalâ€¦
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. â€¦
###### Suggested Courses
Course of the Month9 days, 20 hours left to enroll