Solved

# Extract # of Years from Date formula

Posted on 2011-02-21
214 Views
Experts,
I have this formula:
=YearsMonthsDays(\$A\$8,\$C\$8,\$D\$4,\$D\$5)

and it returns X Years, Y Months and Z Days

I need to incorporate the # of Years into a formula I am using
How can I extract the Years from the YearsMonthsDays formula?

Lets say that the YearsMonthsDays = 10 years and 5 months and 10 days...I would want the answer to be 10 only and no fraction of years.

0
Question by:pdvsa
• 2

LVL 50

Expert Comment

ID: 34947278
It isn't an inbuilt formula, it is a User Design Function (UDF)

Can you please post the code that sits behind this UDF

Cheers

Dave
0

LVL 50

Accepted Solution

barry houdini earned 500 total points
ID: 34947315
Like your other question you could extract that from the result, so if you have this text in B2

10 years and 5 months and 10 days

you can get the years with

=LEFT(B2,FIND(" ",B2)-1)+0

regards, barry
0

Author Closing Comment

ID: 34947342
thanks Barry...   Yes, it was not a UDF, which was a good question to ask and I failed to mention that.  I really forgot that is was not a UDF.
0

LVL 50

Expert Comment

ID: 34947403
Assuming it was a UDF you would be better off tweaking the UDF function internally for a direct answer rather than manipulating the output

For example you can use an Optional variable to dictate years only

Cheers

Dave
0

## Featured Post

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directiâ€¦
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.