+ Reply to Thread
Results 1 to 10 of 10

Supressing 0's in a Datedif formula...

  1. #1
    Forum Contributor
    Join Date
    11-13-2013
    Location
    California
    MS-Off Ver
    Excel 365 Apps for enterprise
    Posts
    180

    Supressing 0's in a Datedif formula...

    I have a formula that I use to get the length of employment for someone, however, I would really love it there was a way to supress parts if the results is a 0.

    The formula I am using is:
    =DATEDIF([@[Hire Date]],[@[Term Date]],"Y")&" year(s) "&DATEDIF([@[Hire Date]],[@[Term Date]],"ym")&" month(s) "&DATEDIF([@[Hire Date]],[@[Term Date]],"md")&" day(s) "

    I the year, month, or days is 0, I don't want to see it. So if someone has been employed for only 90 days, I don't want to see 0 years, 0 months, 90 days. I just want to see 90 days.

    Help?
    Last edited by JennOlsen; 09-05-2014 at 01:58 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-07-2014
    Location
    Washington DC
    MS-Off Ver
    2007
    Posts
    1,047

    Re: Supressing 0's in a Dateif formula...

    Is "=DATEIF" a UDF? I've never heard of that function. Could you possibly upload a sample file?

  3. #3
    Forum Contributor
    Join Date
    11-13-2013
    Location
    California
    MS-Off Ver
    Excel 365 Apps for enterprise
    Posts
    180

    Re: Supressing 0's in a Dateif formula...

    Here's the sample. It's in the Raw Data tab.
    Attached Files Attached Files
    Last edited by JennOlsen; 09-05-2014 at 02:07 PM.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Supressing 0's in a Datedif formula...

    =DATEDIF() needs 2 (real) dates to work with, then an argument...
    =IF(DATEDIF(A1,B1,"y")=0,"",DATEDIF(A1,B1,"y")&" years ")&IF(DATEDIF(A1,B1,"ym")=0,"",DATEDIF(A1,B1,"ym")&" months ")&DATEDIF(A1,B1,"md")&" days"
    =DATEDIF(A1,B1,"y")...will give years
    =DATEDIF(A1,B1,"m")...will give months
    =DATEDIF(A1,B1,"d")...will give days
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Contributor
    Join Date
    11-13-2013
    Location
    California
    MS-Off Ver
    Excel 365 Apps for enterprise
    Posts
    180

    Re: Supressing 0's in a Datedif formula...

    Quote Originally Posted by FDibbins View Post
    =DATEDIF() needs 2 (real) dates to work with, then an argument...
    =IF(DATEDIF(A1,B1,"y")=0,"",DATEDIF(A1,B1,"y")&" years ")&IF(DATEDIF(A1,B1,"ym")=0,"",DATEDIF(A1,B1,"ym")&" months ")&DATEDIF(A1,B1,"md")&" days"
    =DATEDIF(A1,B1,"y")...will give years
    =DATEDIF(A1,B1,"m")...will give months
    =DATEDIF(A1,B1,"d")...will give days
    This worked perfect.

    Thanks!

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Supressing 0's in a Datedif formula...

    id have thought there would be at least 2 months in 90 days
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  7. #7
    Forum Contributor
    Join Date
    11-13-2013
    Location
    California
    MS-Off Ver
    Excel 365 Apps for enterprise
    Posts
    180

    Re: Supressing 0's in a Datedif formula...

    Quote Originally Posted by martindwilson View Post
    id have thought there would be at least 2 months in 90 days
    Well, yes, there is of course. It was more just an example. No need to pick at my momentary brain lapse, lol.

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Supressing 0's in a Datedif formula...


  9. #9
    Forum Contributor
    Join Date
    11-13-2013
    Location
    California
    MS-Off Ver
    Excel 365 Apps for enterprise
    Posts
    180

    Re: Supressing 0's in a Datedif formula...

    Quote Originally Posted by martindwilson View Post
    Very informative. Thank you.

  10. #10
    Valued Forum Contributor
    Join Date
    07-07-2014
    Location
    Washington DC
    MS-Off Ver
    2007
    Posts
    1,047

    Re: Supressing 0's in a Datedif formula...

    Interesting. Thanks.

+ 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. Sort age with dateif formula - no leading zeros
    By eburt in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-04-2013, 11:01 PM
  2. Conbine formula DATEIF with today's date
    By Kimston in forum Excel General
    Replies: 3
    Last Post: 02-25-2012, 03:41 PM
  3. supressing printing msg box
    By z0rpia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2009, 12:30 AM
  4. Dateif formula
    By Get_Involved in forum Excel General
    Replies: 1
    Last Post: 08-12-2008, 07:53 PM
  5. Dateif Formula
    By vbehler in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-19-2007, 10:39 PM

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