Solved

Extract # Days and Months from Formula

Posted on 2011-02-21
13
796 Views
Last Modified: 2012-08-14
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 Months and Days into a formula I am using
How can I extract the Months from the YearsMonthsDays formula and convert that to days?

Lets say that the YearsMonthsDays = 10 months...I would want the 10 months to convert to 10*30 = 300 days but in addition to that I would want to add the number of days that was in the formula.  So, if there was 10 months and 10 days then the answer would be 300+10 = 310 days.

If there were Years involved then I would have to strip the years from the conversion to days.  I am only interested in Days...not the # days in the year.

I hope this makes sense...please ask if need additional information.
thank you
0
Comment
Question by:pdvsa
  • 3
  • 3
  • 3
  • +3
13 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 34946842
Since not all months have 30 days, simply multiplying the number of months by 30 seems a pretty inaccurate way to go about this.

Consider:

Suppose you had a result of 5 years, 11 months, 30 days.

Your approach would call that 360 days, when the right answer should be either 364 or 365, depending on leap years.
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 34946851
It seems to me that it might be easier to extract that information from the input cells rather than use your function and then convert to something else, what inputs do you have for $A$8, $C$8, $D$4 & $D$5, perhaps the total days can be calculated from those?

regards, barry
0
 
LVL 41

Expert Comment

by:dlmille
ID: 34946852
Would you kindly share what goes into $A$8,$C$8,$D$4,$D$5 ?  for one of your cells.

Dave
0
 
LVL 11

Expert Comment

by:Runrigger
ID: 34946862
What are the values that feed that formula?

I assume that it is a user defined function, can you post the code behind it?
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 34946883
Despite my earlier comment this formula should extract the months *30 +days from the data, assuming it's in cell B2

=SUM(MID(B2,FIND({"mon","day"},B2)-3,2)*{30,1})

but I agree with Patrick, you might get a more accurate number if you know the actual dates

regards, barry
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
ID: 34946902
Sorry, best to change to SEARCH....

=SUM(MID(B2,SEARCH({"mon","day"},B2)-3,2)*{30,1})

regards, barry
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 34946946
If you assume the "start day" is in B1 and the "end day" is in B2, then this formula appears to be getting the remaining days after years have been taken into account:

=B2-DATE(YEAR(B2)-(B2<DATE(YEAR(B2),MONTH(B1),DAY(B1))),MONTH(B1),DAY(B1))
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34947133
pdvsa,

Might

=DATEDIF(StartDate,FinishDate,"d")

do what you want?

Patrick(ab)
0
 

Author Comment

by:pdvsa
ID: 34947158
GEEZ...did not think I would have had a response yet.

It does not have to be accurate and this is why I just chose to use 30 days for each month.  

let me test em...be back...
0
 

Author Comment

by:pdvsa
ID: 34947240
OK barry's worked as did all the rest. I will have to award pts to barry though.  I would like to split but I dont believe that is fair since it is first answer that helped me solve problem...

I will be posting another question just like this but will strip the Months and days and leave only the years (1 for 1 year, 2 for 2 years etc...not to worry about fraction thereof... will post in a few min...
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34947270
pdvsa,

>I would like to split but I dont believe that is fair since it is first answer that helped me solve problem...

That's OK with me. Don't worry about it as the decision is very much yours - and you've got a usable answer from Barry.

Patrick
0
 

Author Closing Comment

by:pdvsa
ID: 34947350
thank you.
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34947376
pdvsa,

For the new question try:

=DATEDIF(StartDate,FinishDate,"y")

Patrick
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now