+ Reply to Thread
Results 1 to 4 of 4

If Sat subtract one day, if Sunday subtract tow days

  1. #1
    Forum Contributor
    Join Date
    03-08-2007
    Location
    St. Augustine, Fl
    MS-Off Ver
    Excel 2021 for Mac
    Posts
    392

    If Sat subtract one day, if Sunday subtract tow days

    In Cell C65 I have 3/31/2012 in D65 is Sunday. I have tried this, IF(D65="Sat",=DATE(YEAR(C65),MONTH(C65),DAY(C65)-1)
    That does not work. I can't seem to figure it out.

  2. #2
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: If Sat subtract one day, if Sunday subtract tow days

    if you are just trying to get the last working day (Friday) of the week, you could use the WORKDAY function like this, if your date is in A1:

    =WORKDAY(A1,-1)

    in your formula, the IF function is not in the correct syntax. in case you want to continue with your approach, use this:

    =IF(D65="sat",C65-1,IF(D65="sun",C65-2,""))

    then format the cell containing the formula as DATE (the formula will result in a number, which needs to be converted into a DATE format). in Excel, DATE can be operated upon as a number; subtraction and addition are allowed, which simplifies much of the manipulation related to DATE.

    it is probably better if you share your intent of this formula - there may be better solutions if the overall picture is known.
    - i.s.z -
    CSE, aka Array aka { }, formulae are confirmed with CONTROL+SHIFT+ENTER.
    Replace commas ( , ) with semicolons ( ; ) in formulae, if your locale setting demands.
    All good ideas are courtesy resources from this forum as well as others around the web.
    - e.o.m -

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

    Re: If Sat subtract one day, if Sunday subtract tow days

    Given: IF(D65="Sat",=DATE(YEAR(C65),MONTH(C65),DAY(C65)-1)
    1. If you have the words Saturday or Sunday in cell D65, you would have to test using:
    a) the whole word, i.e., IF(D65="Saturday"... or,
    b) The left three letters: IF(Left(D65,3)="Sat"...

    2. The "=" in front of DATE does not belong.
    3. Given a date in C65, just add or subtract a number from the date itself since dates in Excel are just the count of days since 01/01/1900 formatted by Excel as dates (03/31/2012 = 40999).

    Therefore, try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Match looks in the {} list for the value that matches D65 and returns its place in the list. If the value in D65 is not in the list, MATCH returns #NA. The IFERROR() function is used to convert the #NA to zero (in this case)

    So, the result is that the formula will subtract 1,2 or 0 from the date in C65.
    Last edited by protonLeah; 06-30-2012 at 03:20 PM.
    Ben Van Johnson

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: If Sat subtract one day, if Sunday subtract tow days

    Hi,

    How about an example of what I think you want? See attached.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ 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