cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

SOLVED
Highlighted

## How to calculate the age between 2 dates

Is there any way in Prime 3.0 to calculate the age in years based from 2 dates?

As there are no components (in MC 15 it was possible) in Prime 3.0.

I would need it in a programm routine.

Is it possible with excel component?

thanks

Walter

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

## Re: How to calculate the age between 2 dates

If you need to write it into a program then you may need to write several components to do it.

First (as attached) you can convert the string date, assuming a standard format, to day month & year in numeric format.

Second will do the 'subtraction' but it will need additional statements to tidy up over & underflows on days & months and what happens if the years difference is negative.

Might not be an issue for your specific instance but could be a useful addition to a function library.

Regards

Andy

24 REPLIES 24
Highlighted

## Re: How to calculate the age between 2 dates

Hi walter,

See attached, hope it helps

regards

Andy

Highlighted

## Re: How to calculate the age between 2 dates

Andy,

thanks, but how can I use this in a Programm routine?

see attachment and gif pic.

thanks

Walter

Highlighted

## Re: How to calculate the age between 2 dates

The worksheet here: Date Calendar and Time functions.mcd contains a set of functions that are not based on components. I haven't tried coverting them to Prime though.

Highlighted

## Re: How to calculate the age between 2 dates

Thanks Richard, I had this in my MC 15 sheet. But Prime does not support the VB Script component - so I think at thsi time there is no way to run it in Prime 3.0

Best regards

Walter

Highlighted

## Re: How to calculate the age between 2 dates

You may use the function DayNumber() from Richards worksheet. It does not rely on scripted components and should work for Prime, too.

Highlighted

## Re: How to calculate the age between 2 dates

If you need to write it into a program then you may need to write several components to do it.

First (as attached) you can convert the string date, assuming a standard format, to day month & year in numeric format.

Second will do the 'subtraction' but it will need additional statements to tidy up over & underflows on days & months and what happens if the years difference is negative.

Might not be an issue for your specific instance but could be a useful addition to a function library.

Regards

Andy

Highlighted

## Re: How to calculate the age between 2 dates

Thanks Andy, I could make it!

Highlighted

## Re: How to calculate the age between 2 dates

Hi Walter,

Added a few more lines to the programs - hope it helps

Regards

Andy

Highlighted

## Re: How to calculate the age between 2 dates

Yes, it sheems to be perfect now! Thanks

Highlighted

## Re: How to calculate the age between 2 dates

There are functions at the end of the worksheet that do not use scripted components

Highlighted

## Re: How to calculate the age between 2 dates

Convert to Julian, subtract, then convert back?

Highlighted

## Re: How to calculate the age between 2 dates

fe. BirthDate=1/1/1990

Date2=1/1/2013

age= Date2 - BirthDate = 23.0 years

HOw convert to Julian?

Highlighted

Highlighted

## Re: How to calculate the age between 2 dates

Thanks, littel complicated but ready to enrich my knowledge.

walter

Highlighted

## Re: How to calculate the age between 2 dates

We can do it by Excel help too

Highlighted

## Re: How to calculate the age between 2 dates

 Valery Ochkov wrote:We can do it by Excel help too

Andy already showed the use of an Excel component in the very first answer.

But Walter is in need of a function which can be called from a program.

How would you turn an Excel component into a function?

Highlighted

## Re: How to calculate the age between 2 dates

 Werner Exinger wrote:Valery Ochkov wrote:We can do it by Excel help tooAndy already showed the use of an Excel component in the very first answer.

Sorry, but I did not seen any picture: Highlighted

## Re: How to calculate the age between 2 dates

Walter needs a function and unfortunately it seems we cannot turn the Excel component into a function (like: DeltaD(d1,d2):=...) as we can do with a solve block.

Highlighted

## Re: How to calculate the age between 2 dates

It would be nice to have something like this attached MC15 sheet that accounts for leap years in Prime 3.

Norm

Highlighted

## Re: How to calculate the age between 2 dates

The leap year handling in this sheet is done outside the scripted component so you can use it as well in Prime.

The only routine which won't work in Prime is SplitDate().

Given that date usually is not given as "15 May 1980" but rather as "15.5.1980" (or "5-15-1980" in other countries) it should be not that difficult to write a Prime only routine to split.

The drawback is of course that without VBScript we have no access to the default date format of the underlying OS.

Highlighted

## Re: How to calculate the age between 2 dates

My attempt in P3 (attached) that matches the MC15 results.

I hope this helps.

Highlighted

## Re: How to calculate the age between 2 dates

Thank you very much, Norm. Now I can also calculate the years behind the comma.

Highlighted

## Re: How to calculate the age between 2 dates

How displayed in the plot two points with dates, such as "01/04/1767" and "05/05/1768"? That is not just displayed the year ("1767", "1768"), but also to consider number of days (just a sum them to a year?). Highlighted