Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there any standard formula to de 4

Status
Not open for further replies.

crabsodyinblue

Programmer
Aug 22, 2001
14
0
0
Is there any standard formula to determine the time elapsed between 2 dates and express it in days , months , years.

I have 2 dates date of birth DD/MM/YY and today's date DD/MM/YY

I have a cobol program which I call to calculate the person's age in years , months and days , however the problem is in the definition of a month.

For example

04th Mar YY to 04th Apr YY is classed as 1 month

but if the start date is 28th Feb , what date would anyone say that the following month ended , would it be
a) 28th of March or
b) 31st March

Has anyone had similar problems , is there any set formula or definition for a month or is it similar to the question How long is a piece of string ?


 
Some programs I've seen will translate both dates into the Julian date format, then make the subtraction to find the elapsed time. The Julian format uses days and years, without using months, and so you get an exact answer.

Then you can re-translate the answer back into Gregorian (MM/DD/YYYY) or format your answer in terms of years and months. There are usually utility programs available to make the date format conversions.

Hope this helps, Nina Too
 
Hi,

I had a similar problem in the past. We needed to know the age in months because of some rule with payment, etc.

The thing we did was that if one of the days of the two dates was greater than the last-day-of-the month of one of the dates, we assumed that those days were exactly equal. So we didn't get differences with what people feel as exactly some months.

So yyyy0131 compared to yyyy0228 differs exactly one month because we assume the 31 being 28.

Strange? Yeah! But it works. If you need the amount of months, using days will not be satisfying.

Regards,

Crox
 
Hi Crab,

This is a good example of why we DP types get ourselves into all kinds of trouble. We assume too much of the burden.

This is the USER's problem. It's our responsibility to present the anomalies shown here and ask the user how he'd like the situation handled. Granted his answer may generate other problems/issues, then they s/b handled similarly.

When smeone asks for something like that he MUST be perfectly clear as to what he's expecting. If he can't articulate it, how are you supposed to code it?

Regards, Jack.
 
Thanks to all for replying to the query I posted, I did get round the problem by doing something similar to what CROX suggested.

It is just one of those crazy situations that there is no hard and fasy rule and the problem is open to interpretation. From your answers it seems the solution that myself and colleagues came up with was probably as good as you can get, it was just good to hear that others have come across a similar situation.

Regards
crabsodyinblue
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top