Link to home
Start Free TrialLog in
Avatar of Escanaba
EscanabaFlag for United States of America

asked on

Excel - Calculation On Dates

Hello,

I'm trying to come up with a formula that will look at a hire date and end of year date.  If the total months exceeds 9 months, then the statement is true.  Less than 9 months the statement is false.  For example, an employee is hired 08/15/2013 and the end of year date is 12/31/2013.  Since the total time of employment is less than 9 months the statement would be false.

Any recommendations?
Avatar of Ken Butters
Ken Butters
Flag of United States of America image

there are probably a lot of ways to do this..

1)  use the analysis toolpak described here: http://office.microsoft.com/en-us/excel-help/edate-HP005209073.aspx   This would allow you to subtract 9 months from the end of year date, and compare it to your hire date to see which is greater.

2) compare your hire date to March 31 of the current year.  If the hire date is less than march 31 of the current year... then you would have value of true.
ASKER CERTIFIED SOLUTION
Avatar of spattewar
spattewar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rgonzo1971
Rgonzo1971

Hi,

Attention if the person is hired April 1st is True or False then you have to compare accordingly

Regards
@spattewar   Note : the only reason I would probably try to avoid Datedif is because it doesn't handle the calculation properly when the later month has fewer days in it that the earlier month.

For example... April has 30 days, and January has 31 days.

If you do a datedif on those to dates the result will be 2.  However January 31 to April 30 is 3 months not 2.  

In this case when we are using end of year, you would be ok because the later date happens to be December 31, and you never have more than 31 days in a month... but at any rate it is something to be aware of when you do date calculations.  

That is what the EDATE from the analysis tookpak corrects.

If exactly 9 months is an issue one way or another, then you can always adjust by one day as necessary.
Yes Ken. That is correct but it would work in this scenario. Thanks for putting the information.
Hi all.


Would it be good to use the YEARFRAC function?  In Office 2013 it looks like this from the help file, and I added my own data in column G to test it.  There are remarks in the help file stating the function YEARFRAC may not work properly with dates entered as text, yet it appears that is what they did in the example.  I at least formatted my date cells in column G to be date format and it seems to work.

Here is how it looks showing 9 month IF statement...
User generated image

and here it is showing YEARFRAC function...
User generated image
The number of days of nine months are

2009-01-25      2009-10-25      273
2009-02-25      2009-11-25      273
2009-03-25      2009-12-25      275
2009-04-25      2010-01-25      275
2009-05-25      2010-02-25      276
2009-06-25      2010-03-25      273
2009-07-25      2010-04-25      274
2009-08-25      2010-05-25      273
2009-09-25      2010-06-25      273
2009-10-25      2010-07-25      273
2009-11-25      2010-08-25      273
2009-12-25      2010-09-25      274
(2009 was a non-leap year.)

the third column is the simple subtraction between the first two giving the number of days.

=(A2-A1)

It means anyone employed for 272 or less days does not have 9 months
Anyone employed 276 or more days are always employed for at least 9 months.

What to do with the ones with 273-275 days? If it's a legal framework talking about nine months it often have this defined, ask them.

Sometimes calculations are done with 30 day months only, which would mean 270 days.

So, use 270 or 272 days as a limit and clear it with whoever is responsible for policy.

so:
emp date    EOY date    =(B1-A1)>269
Avatar of Escanaba

ASKER

This will work.  Thank you.