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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

How to calculate the age between 2 dates

WalterSchrabmai
7-Bedrock

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

24 REPLIES 24

Hi walter,

See attached, hope it helps

regards

Andy

Andy,

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

see attachment and gif pic.

thanks

Walter

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.

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

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

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

Thanks Andy, I could make it!

Hi Walter,

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

Regards

Andy

Yes, it sheems to be perfect now! Thanks

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

Convert to Julian, subtract, then convert back?

fe. BirthDate=1/1/1990

Date2=1/1/2013

age= Date2 - BirthDate = 23.0 years

HOw convert to Julian?

Thanks, littel complicated but ready to enrich my knowledge.

walter

We can do it by Excel help too

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?

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

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.

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

Norm

Werner_E
24-Ruby V
(To:nas0k)

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.

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

I hope this helps.

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

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

What about the addition of the fractionofyear to 1767?

see the routine in Norm`s sheet.

Top Tags