+ Reply to Thread
Results 1 to 30 of 30

Date Formula which returns 3rd Monday On January

  1. #1
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Date Formula which returns 3rd Monday On January

    I don't understand the formula (especially IF part) on D7. It returns the date (3rd monday on January) which was explained on C7.
    Attached Files Attached Files

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Date Formula which returns 3rd Monday On January

    You're using Excel 2010, so you should take advantage of the WORKDAY.INTL function

    This formula returns the 3rd monday of the referenced month:
    Please Login or Register  to view this content.
    In that formula, in this section: "0111111", 1's flag which days should be ignored (starting with Monday). So "0111111" indicates that every day except Monday should be ignored.

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

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


    1) Why is there "-1"?

    2) Why is there "3"?

    3) What does "0111111" mean?

    4) I also want to understand the logic of the formula in the file.
    Last edited by zanshin777; 12-14-2015 at 09:24 AM.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Date Formula which returns 3rd Monday On January

    Quote Originally Posted by zanshin777 View Post
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    1) Why is there "-1"?
    If the first day of the month is a Monday, it must be counted. Consequently, we start with the last day of the previous month and count from there.
    2) Why is there "3"?
    3 is the number of "workdays" to increment the base date. Since we are only counting Mondays as workdays, the formula returns the 3rd Monday.
    3) What does "0111111" mean?
    As I mentioned in my original post, "0111111" represents the status of each day of the week, beginning with Monday. 1's indicate weekends. 0's indicate workdays.
    4) I also want to understand the logic of the formula in the file.
    If you search the internet for help on that function you'll find the documentation.

  5. #5
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    1) WORKDAY.INTL function was understood but it give NAME error?

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


    2) How about the formula in the file?
    Last edited by zanshin777; 12-15-2015 at 08:06 AM.

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Date Formula which returns 3rd Monday On January

    1) Your formula has flaws.
    You should use one of these formulas:
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    and format that cell to display the date in MM/DD/YYYY format

    Does that help?

  7. #7
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    The results of the book version formula and the you version of formula are different. February 15 and February 18.

    Look at the F8 and D8. Why?
    Last edited by zanshin777; 12-17-2015 at 08:05 AM.

  8. #8
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Date Formula which returns 3rd Monday On January

    In 2010, the 3rd Monday in February is the 15th. And that's what the formula I posted returns.
    H
    2
    Monday, February 01, 2010
    3
    Tuesday, February 02, 2010
    4
    Wednesday, February 03, 2010
    5
    Thursday, February 04, 2010
    6
    Friday, February 05, 2010
    7
    Saturday, February 06, 2010
    8
    Sunday, February 07, 2010
    9
    Monday, February 08, 2010
    10
    Tuesday, February 09, 2010
    11
    Wednesday, February 10, 2010
    12
    Thursday, February 11, 2010
    13
    Friday, February 12, 2010
    14
    Saturday, February 13, 2010
    15
    Sunday, February 14, 2010
    16
    Monday, February 15, 2010

  9. #9
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    I don't understand the first argument of "WORKDAY.INTL" formulas. Why do you substract "1"?

  10. #10
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Date Formula which returns 3rd Monday On January

    The formula returns the 3rd Monday AFTER the start date.
    If the first of the month is a Monday, you need to count it. Consequently, we need to start from the day before the first of the month.
    Examples:
    June 01, 2015 is a Monday.
    This formula will return June 08, 2015 (the first Monday AFTER the start date):
    Please Login or Register  to view this content.
    This formula will return June 01, 2015:
    Please Login or Register  to view this content.
    Does that help?

  11. #11
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    I think this formula is not useful much. I can't use it copy paste for every date. (or Auto Complete)

    Because I have to know -before writing the formula- if the start date is monday or not.

    Why do I use then an Excel formula? Looking calender is easier.
    Last edited by zanshin777; 12-29-2015 at 12:19 PM.

  12. #12
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Date Formula which returns 3rd Monday On January

    You asked why I subtracted 1 from the start date. I posted an explanation and an example.
    That formula was never intended to solve your initial question.

    The other formulas I posted do solve the problem from your first post.

  13. #13
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Date Formula which returns 3rd Monday On January

    Ron's formula does solve the problem is is much more versatile (easily changed to other days of the week or other counts (2nd Monday, 4th Monday for example). I am not sure why you think it would require looking at a calendar?

    The Original Formula does not work:
    First part is obvious, returns January 1, 20xx. Plus...

    The Logic test in the IF statement
    is looking to see if the first of the month is on Sunday (<2) or not

    If that's true then
    7-WEEKDAY(DATE(A1,1,1))+2 effectively adds 8 to the date which we've already determined is a Sunday (7-1+2) which brings us to the second Monday of the month.

    If that's false then
    2-WEEKDAY(DATE(A1,1,1))
    returns a number between 0 and negative 5 which, if it's 0 puts us at the first monday, if it's < 0 then it puts us at the last monday of the preceding month.

    +(3-1)*7
    adds 14 days so if
    January 1st falls on a Sunday, this formula will return the 4th Monday
    if Jan 1 falls on Monday, it returns the 3rd Monday
    If Jan 1 false on Tues-Saturday, it returns the 2nd Monday.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  14. #14
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    What about?

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by zanshin777; 12-29-2015 at 12:32 PM.

  15. #15
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Date Formula which returns 3rd Monday On January

    If you want to create a more complicated formula when a simpler one will work. Go right ahead.
    I prefer to spend my time making things easier for people, not more difficult.

  16. #16
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Date Formula which returns 3rd Monday On January

    I don't understand the confusion with Ron's formula.
    It's quite clever and works very well.

    Why the -1?

    I think you need to first understand what the basic workday function does (disregard the .intl for now)
    Workday adds x number of working days to a given date (the beginning date is NOT included)
    So say the beginning date is a Monday, then Monday + 3 workdays is Thursday (Mon+1=Tue, Mon+2=Wed, Mon+3=Thu)
    So the initial monday would get skipped. That's why the -1 from the begin date.

    Now the "0111111" part is what is special about workday.INTL
    The normal workday function considers Saturday and Sunday as the weekends.
    But you can specify ANY combination of dates to be the 'Weekend' in workday.INTL
    That string is a string of 7 1's or 0's.
    7 numbers representing each day of the week beginning with Monday.
    1 = weekend day, 0 = working day
    so 01111111 indicates Monday as the only working day.
    If you did 1101011, that would have Wednesday and Friday as your working days, and Mon Tue Thu Sat Sun as the weekend days.

  17. #17
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Date Formula which returns 3rd Monday On January

    What about =WORKDAY.INTL(IF(DATE($A$1,1,1)=2, DATE($A$1,1,1)-1, DATE($A$1,1,1)), 3,"0111111")
    DATE($A$1,1,1) = 2 means that the date is set to 1/2/1900, not likely. I'm not sure where this formula came from?

  18. #18
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Date Formula which returns 3rd Monday On January

    Nevermind, misread

  19. #19
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    I tried to create a formula which if first day of month is monday make "-1" if not go regular.

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

  20. #20
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Date Formula which returns 3rd Monday On January

    Quote Originally Posted by zanshin777 View Post
    I tried to create a formula which if first day of month is monday make "-1" if not go regular.
    Why?

    It's not necessary.

  21. #21
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Date Formula which returns 3rd Monday On January

    Here's your sample book with Ron's formula shown in all the nth weekday cells (D7 D8 D10 D12 D13 D15)
    nthweekdayofmonth.xlsx

  22. #22
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    Let say if you would use this formula with Auto Complete.

  23. #23
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Date Formula which returns 3rd Monday On January

    It doesn't actually matter if the start date is actually a monday or not.
    The -1 makes the workday function account for that possibility either way.
    You don't need to 'Remove' the -1 if the date is NOT actually a Monday.

  24. #24
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    Thank you very much

  25. #25
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Date Formula which returns 3rd Monday On January

    You're welcome.

    Credit to Ron Coderre, he posted it.

  26. #26
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    What does that "-7" mean on D9?

  27. #27
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Date Formula which returns 3rd Monday On January

    You're asking for the 'Last' Monday in May.
    That's very ambiguous because you can't specify a number like the 4th or 5th.
    So instead the formula finds the First Monday of June, then subtracts 7 to become the last Monday of May.

  28. #28
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Date Formula which returns 3rd Monday On January

    Why does "-7" mean "days" not "months" or "years"?

  29. #29
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Date Formula which returns 3rd Monday On January

    Why would it be months or years ?

    The -7 is NOT a part of the networkdays function.
    So the -7 acts the same as it would in a function like say:
    =TODAY()-7

    What does the -7 do there?

    Same thing it does in
    NETWORKDAYS(...)-7

    Say A1 = 2015
    =WORKDAY.INTL(DATE($A$1,6,1)-1,1,"0111111")-7
    Networkdays works out the date as the 1st Monday of June 2015, which is 6/1/2015 (or 1/6/2015 if you're using dd/mm format)
    =6/1/2015-7
    =5/25/2015

  30. #30
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Date Formula which returns 3rd Monday On January

    When working with time (dates and time), Excel uses Days as the unit of measure. So if you have

    January 12, 2016 8:45 PM and subtract 2, you'll get January 10, 2016 8:45 PM

+ 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 give next monday date from todays date
    By john dalton in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-17-2014, 07:20 AM
  2. [SOLVED] Needing formula for date 4 weeks ago on monday
    By Aroy2416 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-14-2013, 09:25 AM
  3. [SOLVED] Find monday preceeding given-date unless date is a monday
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-10-2012, 07:42 AM
  4. Replies: 1
    Last Post: 07-01-2012, 10:25 PM
  5. Replies: 5
    Last Post: 01-31-2012, 08:48 PM
  6. Auto show date for 1st Monday in January
    By JamesT1 in forum Excel General
    Replies: 3
    Last Post: 11-23-2009, 07:54 PM
  7. Formula has to take Monday if due date falls on a Sunday
    By Revathi in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-28-2006, 07:15 AM

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