Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- How to calculate the age between 2 dates

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
04:53 AM

11-26-2013
04:53 AM

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

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
09:12 AM

11-26-2013
09:12 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
06:27 AM

11-26-2013
06:27 AM

Re: How to calculate the age between 2 dates

Hi walter,

See attached, hope it helps

regards

Andy

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
06:40 AM

11-26-2013
06:40 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
08:01 AM

11-26-2013
08:01 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
08:30 AM

11-26-2013
08:30 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
09:06 AM

11-26-2013
09:06 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
09:12 AM

11-26-2013
09:12 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
10:32 AM

11-26-2013
10:32 AM

Re: How to calculate the age between 2 dates

Thanks Andy, I could make it!

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
11:01 AM

11-26-2013
11:01 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
02:14 PM

11-26-2013
02:14 PM

Re: How to calculate the age between 2 dates

Yes, it sheems to be perfect now! Thanks

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
09:32 AM

11-26-2013
09:32 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
08:57 AM

11-26-2013
08:57 AM

Re: How to calculate the age between 2 dates

Convert to Julian, subtract, then convert back?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
09:14 AM

11-26-2013
09:14 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
09:48 AM

11-26-2013
09:48 AM

Re: How to calculate the age between 2 dates

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
10:34 AM

11-26-2013
10:34 AM

Re: How to calculate the age between 2 dates

Thanks, littel complicated but ready to enrich my knowledge.

walter

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
11:59 AM

11-26-2013
11:59 AM

Re: How to calculate the age between 2 dates

We can do it by Excel help too

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
12:02 PM

11-26-2013
12:02 PM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
05:16 PM

11-26-2013
05:16 PM

Re: How to calculate the age between 2 dates

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:

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
07:02 PM

11-26-2013
07:02 PM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
01:24 PM

11-26-2013
01:24 PM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
01:47 PM

11-26-2013
01:47 PM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
10:02 PM

11-26-2013
10:02 PM

Re: How to calculate the age between 2 dates

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

I hope this helps.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-27-2013
03:22 AM

11-27-2013
03:22 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-28-2013
02:34 AM

11-28-2013
02:34 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-28-2013
05:36 AM

11-28-2013
05:36 AM

Re: How to calculate the age between 2 dates

What about the addition of the fractionofyear to 1767?

see the routine in Norm`s sheet.