I use excel to track hire and term dates of employees. My line of work is seasonal so employees get termed and rehired on a regular. Column C is the first hire date, D first term, E second hire date, F second term date and so on.
With this setup, I want to calculate the total amount of time a person has worked here in years, months and days. So I need to calculate the date difference between F and E and the difference between D and C, then add those differences together.
I started with this as my base formula (it's since grown to include up to 5 hire and 5 term columns):
=DATEDIF(C2,C2+((F2-E2)+(D2-C2)),"Y")&" Y "&DATEDIF(C2,C2+((F2-E2)+(D2-C2)),"YM")&" M "&DATEDIF(C2,C2+((F2-E2)+(D2-C2)),"MD")&" D "
And this works well except that some people have never been terminated, while some have been hired and termed 5 times or more so there are empty cells all over the place. I needed to tell the formula that, if a date cell is blank, use today's date. This is what I came up with:
=DATEDIF(C2,C2+((IF(F2,F2,TODAY())-IF(E2,E2,TODAY()))+(IF(D2,D2,TODAY())-IF(C2,C2,TODAY()))),"Y")&" Y "&DATEDIF(C2,C2+((IF(F2,F2,TODAY())-IF(E2,E2,TODAY()))+(IF(D2,D2,TODAY())-IF(C2,C2,TODAY()))),"YM")&" M "&DATEDIF(C2,C2+((IF(F2,F2,TODAY())-IF(E2,E2,TODAY()))+(IF(D2,D2,TODAY())-IF(C2,C2,TODAY()))),"MD")&" D "
It works for most of my employees but not others and I cannot find a rhyme or reason.
I've tried making sure my columns are appropriately date formatted and I've gone so far as to try and restart from scratch but nothing I do makes the calculation work consistently. I'll have two employees who have been hired/termed the same number of times and the formula works for one and not the other.
Any ideas? I've attached a redacted copy of my spreadsheet for reference.
Bookmarks