+ Reply to Thread
Results 1 to 7 of 7

If-Then statement not properly displaying duration (G18) of two dates (E18 & F18)

Hybrid View

  1. #1
    Registered User
    Join Date
    06-07-2018
    Location
    Raleigh, NC
    MS-Off Ver
    MS Office 2016
    Posts
    4

    Post If-Then statement not properly displaying duration (G18) of two dates (E18 & F18)

    E18 - Start Date (5/7/18)
    F18 - End Date (5/10/19)
    G18 - Duration in days (# days)

    G18 has the following formula:
    =IF(AND(DATEDIF(E19,F19,"yd")=0),"1",DATEDIF(E19,F19,"yd"))&IF(DATEDIF(E19,F19,"yd")=1," day"," days")

    I dragged G18 down to apply the formula to the rows below it (ie. G19, G20, G21, etc.), however E19/F19, E20/F20, E21/F21, etc. don't have any dates in them yet, so I want to keep G19, G20, G21, etc. blank.

    Currently, G19, G20, G21, etc. have "1 day" in them, which I don't want. It should be blank, but with the formula running for when dates are entered in E and F. Any suggestions? Thanks!
    Last edited by anujual; 06-07-2018 at 12:46 PM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,844

    Re: If-Then

    Try

    =IF(OR(E18="",F18=""),"",IF(AND(DATEDIF(E19,F19,"yd")=0),"1",DATEDIF(E19,F19,"yd"))&IF(DATEDIF(E19,F19,"yd")=1," day"," days"))

  3. #3
    Registered User
    Join Date
    06-07-2018
    Location
    Raleigh, NC
    MS-Off Ver
    MS Office 2016
    Posts
    4

    Re: If-Then

    Thank you JohnTopley! I tried it out, and it worked to make G19/G20/G21,etc. blank.
    Last edited by anujual; 06-07-2018 at 12:24 PM.

  4. #4
    Registered User
    Join Date
    06-07-2018
    Location
    Raleigh, NC
    MS-Off Ver
    MS Office 2016
    Posts
    4

    Re: If-Then

    One last edit, this was weird when I tried to play around with the formula. I tried two of the following inputs for dates.

    5/7/18 to 5/7/18...resulted in...'1 days' ---> using days for one is awkward. Is there a way to make these two both '1 day'?

    5/7/18 to 5/8/18...resulted in...'1 day'

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,780

    Re: If-Then

    Welcome to the forum! Please take a moment to re-read forum rule #1 and then amend your thread title to something that better explains your problem. Changing your thread title is not optional, which means you must change it. Thanks!

    • Use concise, accurate thread titles.
    • Your post title should describe your problem, not your anticipated solution.
    • Use terms appropriate to a Google search - poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice tell us nothing.
    • Responding to a request to change your thread title by doing so is mandatory.

    To change a title go to your first post, click EDIT then Go Advanced and change your title.

    No help to be offered, please, until the OP complies with this request.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  6. #6
    Registered User
    Join Date
    06-07-2018
    Location
    Raleigh, NC
    MS-Off Ver
    MS Office 2016
    Posts
    4

    Re: If-Then

    Thank you AliGW - it's updated!

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,844

    Re: If-Then

    Try

    =IF(OR(E19="",F19=""),"",IF(DATEDIF(E19,F19,"yd")<=1,"1 day",DATEDIF(E19,F19,"yd")&" days"))

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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