+ Reply to Thread
Results 1 to 3 of 3

Dates Difference with condition

  1. #1
    Registered User
    Join Date
    06-14-2018
    Location
    UAE
    MS-Off Ver
    2000
    Posts
    1

    Dates Difference with condition

    Hi, I am stuck on a small problem. I need to calculate the difference between two dates in two different columns in "days". It needs an example to understand, as given below:

    31-01-2018 - 17-03-2018 = 45 Days
    31-01-2018 - 06-05-2018 = 95 Days

    If the difference between the dates is more than 1 month, I need only "days" calculated from 2nd date only, i.e. "17 Days" in this case.

    Can anybody help me, please? Thanks

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Dates Difference with condition

    this might work, but this assumes a lot.
    =IF(DATEDIF(A2,B2,"d")<31,DATEDIF(A2,B2,"d"),B2-DATEVALUE(MONTH(B2)&"/1/"&YEAR(B2)))

    first, it assumes that these 31-01-2018 - 17-03-2018 are in their own cells, for example A2 and B2 respectively
    second, it assumes that "the dates is more than 1 month" is a 30 day month.
    third, it assumes the way I wrote it will work for you because my system uses mm/dd/yyyy while your dates showed as dd/mm/yyyy.
    fourth, it assumes that when you say "17 days" if greater than 1 month you are meaning that you want the first of the month to be subtracted from the 17th of the month.
    lastly mine returns 16 rather than 17 but that can be adjusted with this change...
    =IF(DATEDIF(A2,B2,"d")<31,DATEDIF(A2,B2,"d"),B2-DATEVALUE(MONTH(B2)&"/1/"&YEAR(B2))+1)
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Valued Forum Contributor Root_'s Avatar
    Join Date
    07-29-2017
    Location
    _
    MS-Off Ver
    2010+
    Posts
    485

    Re: Dates Difference with condition

    Is this what you need?

    =IF(A2>=EDATE(B2,-1),B2-A2,DAY(B2))

+ 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. if condition for dates difference
    By vimalanathk in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-07-2017, 11:56 PM
  2. Difference in Dates, with Default Condition
    By bdav1216 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-24-2017, 10:41 AM
  3. 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
  4. 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
  5. Replies: 4
    Last Post: 02-21-2011, 12:44 PM
  6. Replies: 0
    Last Post: 09-30-2010, 11:04 AM
  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