Jump to content

Defining problem? Years, Months, Days


This topic is 5007 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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.

Link to comment
Share on other sites

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 by Guest
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Guest
Changed the last sentence.
Link to comment
Share on other sites

  • 1 month later...

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 by Guest
I should have replied to myself and not LaRetta. Is there a way to delete a post?
Link to comment
Share on other sites

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 )

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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"

)

Link to comment
Share on other sites

This topic is 5007 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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