David Jondreau Posted July 8, 2010 Posted July 8, 2010 A client, given a birthdate, wants to know the age of contacts in Year, Months, and Days. I built a function that I thought covered all the bases, but in testing it I kept getting results I didn't expect. I think the problem is how an age in how I'm defining YMD. I would simply say that a person is x number of years for the years completed, y number of months for the months completed and z number of days. How would you define the age of someone in YMD? Please do a sanity check for me: Today is 3/1/2010. Joe is born on 12/31/85. How old is he? Jill is born on 12/30/85. How old is she? Express ages in Year, Months, and Days.
comment Posted July 8, 2010 Posted July 8, 2010 See (for example): http://fmforums.com/forum/showtopic.php?tid/183910/
Raybaudi Posted July 8, 2010 Posted July 8, 2010 James is born on 2/29/1984 and Jane is born on 2/28/1984: how hold are they ?
David Jondreau Posted July 9, 2010 Author Posted July 9, 2010 See (for example): http://fmforums.com/forum/showtopic.php?tid/183910/ OK, I'm not crazy. And I can confidently go back to the client and clarify the issue.
David Jondreau Posted July 9, 2010 Author Posted July 9, 2010 (edited) James is born on 2/29/1984 and Jane is born on 2/28/1984: how hold are they ? I don't think that's one of the exceptions... I would say: James is 26 years, 5 4 months, and 10 days. Jane is 26 years, 5 4 months, and 11 days. The issue I've come across is when a person is born on a day in the birth month that doesn't exist in the previous month of the current date. As per my original post. Edited July 9, 2010 by Guest
comment Posted July 9, 2010 Posted July 9, 2010 Just one more note: you CAN express the age in Y,M,D, according to any arbitrary rules you choose. However, no matter which method you follow, the rules of arithmetic difference will not apply to the results. Here are two examples of rules that you cannot expect to hold true: If: a + b = c Then: c - b = a If: a + b = c AND d + b = c Then: a = d
Raybaudi Posted July 9, 2010 Posted July 9, 2010 I don't think that's one of the exceptions... I would say: James is 26 years, 5 4 months, and 10 days. Jane is 26 years, 5 4 months, and 11 days. So Jane is clearly older ( 1 day ) than James. Now, based on your assumption, give me the resut if today is 2/28/2010... They have both completed 26 years, both completed their months...
David Jondreau Posted July 9, 2010 Author Posted July 9, 2010 I'm not sure the point you're trying to make unless it's the same one as my original post.
Raybaudi Posted July 9, 2010 Posted July 9, 2010 Yes, in your original post you said: "I would simply say that a person is x number of years for the years completed, y number of months for the months completed and z number of days" Based on that assumption, on 2/28/2010 they are both 26 years old.
Raybaudi Posted July 9, 2010 Posted July 9, 2010 Here are two examples of rules that you cannot expect to hold true: If: a + b = c Then: c - b = a If: a + b = c AND d + b = c Then: a = d I do not get this one... both rules are true.
comment Posted July 10, 2010 Posted July 10, 2010 Based on that assumption, on 2/28/2010 they are both 26 years old. Well, then they were born on the same day, according to rule #2.
LaRetta Posted July 10, 2010 Posted July 10, 2010 (edited) Daniele, take a look at this link about non sequitur and scan down to "Affirming the Consequent". The truth of the conclusion is independent of the truth its premises - it is a 'non sequitur'. Edited July 10, 2010 by Guest Changed the last sentence.
David Jondreau Posted September 2, 2010 Author Posted September 2, 2010 (edited) All right. Finally heard from the client on how they want to define age. The basically want to treat Year, Month, and Date as separate digits and subtract. Months are 30 days and Years are 12 months. Today Year.TodayMonth.TodayDay -BirthYear.BirthMonth.BirthDay _______________________________ Years.Months.Days I solved it ugly: Let([ birthdate = People::Birthdate; today = Get(CurrentDate); bday =Birthdate; error = IsEmpty(bday) ; //Days dToday = Day(Today); dBday = Day(bday) ; dCarry = (dToday < dBday ); dToday = (dToday + (dCarry*30)); days = dToday -dBday; dResult = days & " day" & If(days ≠ 1; "s") & " " ; //Months mToday = Month(Today) - dCarry; mBday = Month(bday); mCarry = (mToday < mBday); mToday = (mToday + (mCarry*12)); months = (mToday - mBday); mResult = months & " month" & If(months ≠ 1; "s") & " " ; //Years yToday = Year(Today) - mCarry; yBday = Year(bday); years = (yToday - yBday); yResult = years & " year" & If(years ≠ 1; "s") & " " ; result = yResult & " " & mResult & " " & dResult; result = Case(error; ""; result) ]; result ) But two things... -I'm sure there's an eleganter way to achieve this result. -The client also want to calculate how many months and days until an pregnant woman's due date. Any thoughts on that? Thanks, DJ Edited September 2, 2010 by Guest I should have replied to myself and not LaRetta. Is there a way to delete a post?
comment Posted September 2, 2010 Posted September 2, 2010 Try: n = Date2 - Date1 ; y = Div ( n ; 360 ) ; m = Div ( Mod ( n ; 360 ) ; 30 ) ; d = Mod ( n ; 30 ) The client also want to calculate how many months and days until an pregnant woman's due date. Any thoughts on that? Same thing - except you don't need the year part, so: m = Div ( n ; 30 ) ; d = Mod ( n ; 30 )
David Jondreau Posted September 2, 2010 Author Posted September 2, 2010 n = Date2 - Date1 ; y = Div ( n ; 360 ) ; m = Div ( Mod ( n ; 360 ) ; 30 ) ; d = Mod ( n ; 30 ) I appreciate the help, but this doesn't give the result for which the client is looking. The formula they use works out like this...If a child was born on June 8th, 2007 and today is September 2nd, 2010: 2010 09 02 -2007 06 08 _______________ 0003y 02m 24d If Day(Today)< Day(BDay); 30 days gets carried over from the months column.
comment Posted September 2, 2010 Posted September 2, 2010 So where does this part come in? Months are 30 days and Years are 12 months.
comment Posted September 2, 2010 Posted September 2, 2010 (edited) Or did you perhaps mean: em = 12 * y2 + m2 - 12 * y1 - m1 - ( d1 > d2 ) ; y = Div ( em ; 12 ) ; m = Mod ( em ; 12 ) ; d = Mod ( d2 - d1 ; 30 ) Edited September 2, 2010 by Guest
David Jondreau Posted September 2, 2010 Author Posted September 2, 2010 If the day of the birthdate is greater than today's day, we "carry over" 30 days, not the number of days there really are in the previous month. If the birth month (modified by the above carry over) is greater than today's month, a year gets taken off and 12 months are carried over. A better example may be a birthday of June 8th, 2007 and a current date of May 2nd, 2010. 2010y 05m 02d -2007y 06m 08d _______________ becomes 2009y 16m 32d -2007y 06m 08d _____________ = 0002y 10m 24d Does that make sense? This is literally how they've been doing it by hand , "carry the one" or rather "carry the 30".
Raybaudi Posted September 2, 2010 Posted September 2, 2010 Hi 2010 08 31 2010 07 31 ---------- 0y 1m 0d 2010 09 01 2010 07 31 ---------- 0y 1m 0d So there are 2 days where the guy is one month old.
David Jondreau Posted September 2, 2010 Author Posted September 2, 2010 em = 12 * y2 + m2 - 12 * y1 - m1 - ( d1 > d2 ) ; y = Div ( em ; 12 ) ; m = Mod ( em ; 12 ) ; d = Mod ( d2 - d1 ; 30 ) That certainly give the correct results for a few problem dates. I'm going to need a day and a stiff drink to understand what's going on though.
David Jondreau Posted September 2, 2010 Author Posted September 2, 2010 So there are 2 days where the guy is one month old. Yes, I'm aware of that. That's a compromise the client wants to make...and has been making pre-FMP.
comment Posted September 2, 2010 Posted September 2, 2010 there are 2 days where the guy is one month old. So? I know a woman who was 39 years old for 4 years.
Raybaudi Posted September 2, 2010 Posted September 2, 2010 Then you can try: Let([ n = 360* ( Year ( End ) - Year ( Start ) ) + 30* ( Month ( End ) - Month ( Start ) ) + ( Day ( End ) - Day ( Start ) ) ; y = Div ( n ; 360 ) ; m = Div ( Mod ( n ; 360 ) ; 30 ) ; d = Mod ( n ; 30 ) ]; y & "y " & m & "m " & d & "d" )
Recommended Posts
This topic is 5200 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now