+ Reply to Thread
Results 1 to 8 of 8

Difference in Dates, with Default Condition

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-19-2016
    Location
    Chicago, IL
    MS-Off Ver
    Office 2016 Professional
    Posts
    388

    Difference in Dates, with Default Condition

    H2 is a date field (ex. 01/13/2017)

    AN2 is a date field (ex. 01/12/2017)

    Here is my formula:

    =IF(H2="","-1",IF(AN2="","-1",DATEDIF(AN2,H2,"D")))

    In the example above, my forumula is returning a value of '1' but my formula below is returning a value of #NUM! in situations where H2 is an older date than AN.

    Ex.

    H27 = 12/08/2016 and AN27 = 01/11/2017 returns a #NUM!

    H28 = 01/03/2017 and AN28 = 01/06/2017 returns a #NUM!

    I would like to fix this by modifying my formula to say if the difference in dates is either GE or LE 99, set the value to -1.

    How would I modify my existing formula to accomplish that?
    Last edited by bdav1216; 04-21-2017 at 09:19 PM.

  2. #2
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: Difference in Dates, with Default Condition

    try

    Formula: copy to clipboard
    =IF(H2>=AN2,DATEDIF(AN2,H2,"d"),-1)
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  3. #3
    Forum Contributor
    Join Date
    03-19-2016
    Location
    Chicago, IL
    MS-Off Ver
    Office 2016 Professional
    Posts
    388

    Re: Difference in Dates, with Default Condition

    Quote Originally Posted by vlady View Post
    try

    Formula: copy to clipboard
    =IF(H2>=AN2,DATEDIF(AN2,H2,"d"),-1)
    Thank you. How would this be modified to account for blank dates in Column H or AN? When either are blank (or the condition you added), the value of the formula, should be -1.

  4. #4
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2021
    Posts
    5,928

    Re: Difference in Dates, with Default Condition

    Trt this ...

    =IF(COUNT(H2,AN2)<2,-1,MAX(-1,H2-AN2))

  5. #5
    Forum Contributor
    Join Date
    03-19-2016
    Location
    Chicago, IL
    MS-Off Ver
    Office 2016 Professional
    Posts
    388

    Re: Difference in Dates, with Default Condition

    Thank you for the assistance.

    One other variation.

    Column C = Total Time
    Column A = Time1
    Column B = Time2

    (Time1 +Time2 should equal Total Time), but there will be instances where the time's are illogical.

    I need help calculating Column A. It should be calculated from the difference of C - B, but I need to deal with specific illogical conditions.

    1) If Column C = blanks " ", how do I set this to a value of '-1'.
    2) If Column B or C = '-1', then the value of Column A should be set to a value of '-1'.
    3) If the difference of C-B results in a negative value for Column A, the value in Column A should be set to a value of '-1'.

    I attached a sample workbook for reference.
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,666

    Re: Difference in Dates, with Default Condition

    If I understand correctly any of the three conditions, Bn=-1, Cn="" or Bn>Cn, should cause An to display -1. Otherwise An should display the difference in Cn and Bn. If that is correct then try the following formula in A2 and down:
    Formula: copy to clipboard
    =IF(OR(B2=-1,C2="",B2>C2),-1,C2-B2)
    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  7. #7
    Forum Contributor
    Join Date
    03-19-2016
    Location
    Chicago, IL
    MS-Off Ver
    Office 2016 Professional
    Posts
    388

    Re: Difference in Dates, with Default Condition

    Thanks for the formula, this looks to be what I need.

    One quick question. If Column C is blank filled, how do I set the value to -1?

  8. #8
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,666

    Re: Difference in Dates, with Default Condition

    If you are asking how to set the value of C2 to -1 when C2 starts as a blank cell, then I believe that you will need to seek advice from a member that is proficient in VBA, as I don't know of a way to do that by formula. It also appears that I need to make a correction in the formula based on this new understanding. Since the formula that populates column A isn't concerned with whether or not the corresponding value in column C is blank, rather whether or not it contains a value of -1, the formula should read:
    Formula: copy to clipboard
    =IF(OR(B2=-1,C2=-1,B2>C2),-1,C2-B2)
    Let us know if you have any questions.

+ 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. [SOLVED] set a colum as default base on date condition when i open a file
    By ids_73 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-13-2017, 06:15 PM
  2. Compute difference between 2 date/time columns based on a condition
    By kjsivy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-09-2013, 11:29 PM
  3. how to Calculate the difference between two times and apply <= to the condition
    By student_query in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-07-2013, 08:10 PM
  4. Replies: 4
    Last Post: 02-21-2011, 12:44 PM
  5. Replies: 0
    Last Post: 09-30-2010, 11:04 AM
  6. difference between dates
    By Ankur in forum Excel General
    Replies: 2
    Last Post: 08-06-2006, 12:20 PM
  7. Calculating Time difference based on a condition
    By sonnethg in forum Excel General
    Replies: 4
    Last Post: 10-11-2005, 04:25 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