Skip to main content
12-Amethyst
November 26, 2013
Solved

How to calculate the age between 2 dates

  • November 26, 2013
  • 7 replies
  • 10549 views

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

Best answer by AndyWesterman

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

7 replies

12-Amethyst
November 26, 2013

Hi walter,

See attached, hope it helps

regards

Andy

12-Amethyst
November 26, 2013

Andy,

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

see attachment and gif pic.

thanks

Walter

19-Tanzanite
November 26, 2013

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.

12-Amethyst
November 26, 2013

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

25-Diamond I
November 26, 2013

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

1-Visitor
November 26, 2013

Convert to Julian, subtract, then convert back?

12-Amethyst
November 26, 2013

fe. BirthDate=1/1/1990

Date2=1/1/2013

age= Date2 - BirthDate = 23.0 years

HOw convert to Julian?

24-Ruby IV
November 26, 2013

We can do it by Excel help too

25-Diamond I
November 26, 2013

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?

24-Ruby IV
November 26, 2013

Werner Exinger wrote:

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.

Sorry, but I did not seen any picture:

day.png

1-Visitor
November 26, 2013

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

Norm

25-Diamond I
November 26, 2013

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.

1-Visitor
November 27, 2013

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

I hope this helps.

12-Amethyst
November 27, 2013

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

24-Ruby III
November 28, 2013

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

Pic_1.png

12-Amethyst
November 28, 2013

What about the addition of the fractionofyear to 1767?

see the routine in Norm`s sheet.