+ Reply to Thread
Results 1 to 10 of 10

how to use if and date function to return certain values

  1. #1
    Forum Contributor
    Join Date
    07-27-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    145

    how to use if and date function to return certain values

    Hi,
    a column contains dates in date format, contains a date before the column b date
    b column contains today()
    I want c column to get some output, if b-a is more than 5 years (exact days), say 20
    do , if b-a is more than 2 years and less than 5 years, say 40
    do , if b-a is less than 2 years , say 60 otherwise blank
    Please use if condition to get the above results. I have formatted a, b with date formats

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: how to use if and date function to return certain values

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,953

    Re: how to use if and date function to return certain values

    Hint: Try:
    =IF(YEAR(B1)-YEAR(A1) < or > or = to something then post your workbook (with formula)....
    Ben Van Johnson

  4. #4
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,156

    Re: how to use if and date function to return certain values

    hi rajuj. so column B is a repeat of Today's date? can you just place a TODAY() formula in 1 single cell & make them all use that? TODAY is volatile, so Excel calculates it constantly. having so many cells with that is not good. say i put it in E1. also, you mentioned:
    do , if b-a is more than 2 years and less than 5 years, say 40
    do , if b-a is less than 2 years , say 60 otherwise blank
    - what about 2 years? there's more than 2 & less than 2.
    - why is there an "otherwise"? what other options are there? 0 is less than 2 years, so it'll return 60. anything more than 5 is 20.

    maybe:
    =LOOKUP(DATEDIF(A2,$E$1,"y"),{0,3,6},{20,40,60})
    change the parts in red to the minimum years for the numbers to appear. so i'm assuming 0 years get 20, 3 years 40, 6 years 60.

    if the "otherwise" means Column A being blank or a text, then:
    =IF(ISNUMBER(A2),LOOKUP(DATEDIF(A2,$E$1,"y"),{0,3,6},{20,40,60}),"")
    Attached Files Attached Files

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  5. #5
    Forum Contributor
    Join Date
    07-27-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    145

    Re: how to use if and date function to return certain values

    I am enclosing the worksheet , please let me know, if it is for numbers, then it is working, if it is date, that is the difference is in date, to be exact date between the two dates, like the actual days of 30,31 days, then what is the formula,I should use.
    There is a formula days360, but a year has 365 or 366 days.
    What is datedif function, and how to use in this regard.
    Could not i use the if function , as i normally use for nested if function.
    Attached Files Attached Files
    Last edited by rajuj; 01-08-2014 at 12:43 AM.

  6. #6
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,651

    Re: how to use if and date function to return certain values

    DATEDIF(start date,end date,"y") give the exact different years btw two dates (i.e 2/1/2014 and 1/1/2016 = 1 year 364 days => 1 year)
    So you have:
    =IFERROR(LOOKUP(DATEDIF(A1,B1,"y"),{0,2,5},{60,40,20}),"")
    Quang PT

  7. #7
    Forum Contributor
    Join Date
    07-27-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    145

    Re: how to use if and date function to return certain values

    Hi, Thank you beebo it worked, Please explain your formula,
    You have included,0,2,5 , and used iferror
    I am newbie to iferror formula
    Why i was getting the error, when i used in the dated if function like this
    Please see the other sheet and value error.
    I changed the years to days, and used datedif, but i get the error

  8. #8
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,651

    Re: how to use if and date function to return certain values

    rajuh,

    Your formula
    =IF(DATEDIF(A1,B1,"D")>1825,120),IF(DATEDIF(A1,B1,"D")<1825,80)
    must be corrected be remove the bracket into the end:

    =IF(DATEDIF(A1,B1,"D")>1825,120,IF(DATEDIF(A1,B1,"D")<1825,80))

    About IFERROR,
    IFERROR(A,B) returns B IF A is ERROR, of not, A.
    Last edited by bebo021999; 01-08-2014 at 01:26 AM.

  9. #9
    Forum Contributor
    Join Date
    07-27-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    145

    Re: how to use if and date function to return certain values

    Thankkkkk you very much. I should not have bracketed.Hi beboo, will it be correct to the exact days, considering the actual dates falling in future months and years in my formula.
    I have given days, instead of year,month, and days.
    For academic interest, how to substitute these days in years, In excel 5 will not denote 5 years. Is there any other way.
    in your formula 0,2,5 has been entered as array formula.
    Is my formula, correct? after your correction. I think, that actual days may be more or less than actual 365. How to correct , because, any day if entered in a1 should work.
    I think your first formula with modification of 0,2,5 would be exact. pl expecting reply
    Last edited by rajuj; 01-08-2014 at 04:48 AM.

  10. #10
    Forum Contributor
    Join Date
    07-27-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    145

    Re: how to use if and date function to return certain values

    May i expect a reply. what is the use of days 360 formula in excel and how it is different from datedif function. Is it correct to use days360 formulas to subtract days

+ 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] Date function that compare 2 date in single column and return value
    By alimamak in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-20-2012, 06:45 AM
  2. Select a Date between Two Date Rows, then the Column State and return Table Matrix Values
    By InNeedofHelpASAP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 11:03 AM
  3. Due Date, multiple return values.
    By JapanDave in forum Excel General
    Replies: 14
    Last Post: 03-30-2011, 11:03 PM
  4. Replies: 2
    Last Post: 01-20-2011, 04:54 PM
  5. Date Function formula that will return the date of a specific week
    By Greg in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-12-2006, 12:10 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