+ Reply to Thread
Results 1 to 6 of 6

Add multiple Date Dif together to get total length of service, if date blank, use TODAY

  1. #1
    Registered User
    Join Date
    03-29-2022
    Location
    Upstate, NY
    MS-Off Ver
    365, Version 2202
    Posts
    4

    Add multiple Date Dif together to get total length of service, if date blank, use TODAY

    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.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Kanderton; 03-29-2022 at 02:13 PM.

  2. #2
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,066

    Re: Add multiple Date Dif together to get total length of service, if date blank, use TODA

    Part of your problem is that many of what appear to be dates are actually text.

    So you first need to convert all the date cells to actual dates.

    You can detect the problem cells by trying to change the formatting style, you will see that many will remain the same, and they are the ones that are text.

    Another problem is that there are records where the termination is AFTER their rehire date... cell D2 is an obvious example
    Last edited by janmorris; 03-29-2022 at 02:33 PM.
    As a gesture off appreciation, you can click * Add Reputation at the foot of any of the posts of members who helped you reach a solution.

    And finally, was your problem solved? if so, please click Thread Tools above the first post of your enquiry, then select [Solved]

  3. #3
    Registered User
    Join Date
    03-29-2022
    Location
    Upstate, NY
    MS-Off Ver
    365, Version 2202
    Posts
    4

    Re: Add multiple Date Dif together to get total length of service, if date blank, use TODA

    Thank you for your reply Jan. I guess I don't know how to do this appropriately. I'll fully admit I know nowhere near enough about Excel and I've Frankensteined this all together.

    I'm attempting to reformat the date cells C8-L8. I select them all, right click and choose "Format Cells...", I change the "Category" to "Date" and choose "03/14/12" but that doesn't correct the calculation. It's still #NUM! . Am I doing this wrong?Attachment 774640

  4. #4
    Valued Forum Contributor janmorris's Avatar
    Join Date
    07-24-2021
    Location
    Japan
    MS-Off Ver
    Google Sheets (& Mac 2021)
    Posts
    1,066

    Re: Add multiple Date Dif together to get total length of service, if date blank, use TODA

    Changing the format style (eg, from 03/25/2019 to 2019-03-25) will only allow you to detect (see) potential issues, but it wont correct them.

    To convert all dates to the same format:

    1. insert two columns after each date column, for example add two columns after column C.
    2. put this formula into (new column D) cell D2 and drag down:
    Please Login or Register  to view this content.
    3. Put this formula into (new column E) cell E2 and drag down:
    Please Login or Register  to view this content.
    4. select column E
    5. right click and choose "Copy"
    6. right click on column C
    7. choose Paste Special > Values
    now all the dates in column C are the same format

    WARNING!
    because the formatting of the cells is not originally consistent, some dates may switch the month and days (its happening as i type this)

    i would normally have done this to completion and provided the file with dates converted, but as there are so many dates that are not "behaving" with the conversion i am reluctant to provide a file where the data has corrupted (new dates are not appearing the same as old dates) from original.

  5. #5
    Registered User
    Join Date
    03-29-2022
    Location
    Upstate, NY
    MS-Off Ver
    365, Version 2202
    Posts
    4

    Re: Add multiple Date Dif together to get total length of service, if date blank, use TODA

    That's completely understandable. I can manage the reformatting in this manner. Thank you for your assistance!

  6. #6
    Registered User
    Join Date
    03-29-2022
    Location
    Upstate, NY
    MS-Off Ver
    365, Version 2202
    Posts
    4

    Re: Add multiple Date Dif together to get total length of service, if date blank, use TODA

    Thank you so much Jan! This fixed the formatting and, in turn, the formula errors. Much appreciated!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Date of Birth/Age/Today's Date and Blank Cells
    By jdawg1536 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-14-2015, 10:49 PM
  2. [SOLVED] Count blank cells up to today's date
    By LHOWE in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-24-2014, 11:53 AM
  3. Replies: 7
    Last Post: 10-13-2013, 05:11 PM
  4. [SOLVED] Nested if date less then equal today or blank
    By adamcfishman in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-07-2013, 01:43 PM
  5. [SOLVED] Formula to calculate total service date?
    By LDouble3 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-11-2012, 06:20 PM
  6. Assume today's date if blank
    By gdi2k in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-10-2007, 08:36 AM
  7. to enter today's date if a cell is blank
    By Lynn Hanna in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-26-2006, 08:10 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1