+ Reply to Thread
Results 1 to 6 of 6

If formula to show results based on the number of days between two dates

  1. #1
    Registered User
    Join Date
    10-09-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    8

    If formula to show results based on the number of days between two dates

    Hi,

    I need help on the IF formula to show results based on the number of days between two dates using multiple conditions.

    For Ex:

    If col A has date 11/24/2020 and Col B has same date 11/24/2020 then the column C should reflect "T+0"
    If col A has date 11/24/2020 and Col B has same date 11/25/2020 then the column C should reflect :"T+1"
    If col A has date 11/24/2020 and Col B has same date 11/26/2020 then the column C should reflect :"T+2"

    and so on..

    How can I do this using IF formula.

    Appreciate your assistance.

    Thanks,
    Arun

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,695

    Re: If formula to show results based on the number of days between two dates

    Assuming your dates start in A2, allowing for a header row, then you could have this formula in C2:

    =IF(OR(A2="",B2=""),"","T+"&(B2-A2))

    Copy down as required.

    Hope this helps.

    Pete

  3. #3
    Registered User
    Join Date
    10-09-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: If formula to show results based on the number of days between two dates

    Hi Pete,

    Thanks for your assistance. This formula works as per my expectation.
    Just one problem, the result is showing as "T+0.549421296294895", I am not sure how to fix this? Can you help.

    In my excel, the dates in column A & B is in this format "2/11/2020 1:43:03 AM", is this a reason why my result is showing in fraction values?

    Can you help to fix this issue please.

    Thanks,
    Sakthi

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,695

    Re: If formula to show results based on the number of days between two dates

    Yes, times in Excel are stored internally as fractions of a 24-hour day. You can solve the problem by changing the formula to this in C2:

    =IF(OR(A2="",B2=""),"","T+"&(INT(B2)-INT(A2)))

    Hope this helps.

    Pete

  5. #5
    Registered User
    Join Date
    10-09-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: If formula to show results based on the number of days between two dates

    Excellent. This new formula solved my problem.
    Thank you very much for your assistance Pete.

    One last question. This formula works fine if the date is in US format (MM/DD/YYYY), however if I enter the date in UK format (DD/MM/YYYY) it calculates the number of days incorrectly.

    For example:

    US date format(MM/DD/YYYY) :col A has date 02/11/2020 and Col B has date 02/12/2020 and column C is reflecting as "T+1". This is as expected and works fine.
    UK date format(DD/MM/YYYY) :col A has date 02/11/2020 and Col B has date 03/11/2020 and column C is reflecting as "T+29". this is not correct.

    Can you help to fix this formula to work for all date formats.

    Thank you,
    Arun

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,695

    Re: If formula to show results based on the number of days between two dates

    You will need to change your regional settings to UK format before entering UK-style dates, and then back again to US format if you want to enter some dates in that style.

    Alternatively, you could use another column to tell Excel which format you are using for that date (e.g. by entering UK or US), and then another formula could transfer the dates into the appropriate value, and the formula that I gave you earlier would need to take the dates from the new columns.

    It would be easier just to stick to one format. If the dates are coming from a file, then you should manipulate them within that file before pasting them in.

    If that takes care of your original question, please take a moment to select Thread Tools from the menu above and to the right of your first post in this thread, and mark the thread as SOLVED.

    You might also like to know that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

+ 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] Formula to show a Number 1 or 0 based on dates and numbers.
    By sorensjp in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 08-26-2020, 06:41 AM
  2. [SOLVED] Formula needed to compare number of days between dates but exclude negative results
    By bcmilne in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-20-2017, 10:23 AM
  3. Late count based on number of days between two dates for a list of dates
    By Keats713 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-03-2017, 11:03 PM
  4. Late count based on number of days between two dates for a list of dates
    By Keats713 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-03-2017, 06:35 PM
  5. Late count based on number of days between two dates for a list of dates
    By Keats713 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-03-2017, 02:19 PM
  6. Calculate number of days between 2 dates & then assign a number based on the answer
    By MrHappyGoLucky12 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-27-2014, 09:20 PM
  7. [SOLVED] Conditionally format cell based on dates within a number of days apart
    By mjy58 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-24-2013, 06:01 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