How many Mondays between two dates? [homework]

count-of-mondays-between-two-datesHere is a quick but challenging homework problem for you.

Let’s say you have two dates – Start and End.

And you want to find out how many Mondays are there between those two dates (including the start & end dates).

What formula would give the answer?

Please post your formulas / VBA functions / DAX measures in the comments section.

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

138 Responses

    1. If I’m not mistake there are 8 Mondays between 01/12/2015 and
      31/01/2016.
      Your formula retures: 10

  1. Your solution might be a tad more efficient using a numeric test rather than a string test

    =SUMPRODUCT(–(WEEKDAY(ROW(INDIRECT(B1&”:”&B2)))=2))

    It might also be worth pointing out that the dates in B1 & B2 can be any order, B1 does not have to be the earlier date.

    1. Hi Bob,
      Love the solution, very neat and crisp. Even though i use the functions in your solution and i still confused about the row(Indirect(B1&”:”&B2)) bit.

      To take a simple example If B1 was 2 and B2 was 6 what would Indirect(2:6) evaluate to?

      Applying the row function to this then yields the actual values of the reference range (2;3;4;5;6).

      Would you mind explaining a little if its not too much for you?

      Thanks

      Mark

      1. Hi Mark ,

        Let us start from the outside and move inwards.

        It is clear that we need a function to sum values ; since this has to operate on an array of values , SUMPRODUCT is an obvious choice.

        Now we need an array of values , which will have 1 for a Monday , and 0 for all other days of the week. This we can get by using the WEEKDAY function , and checking whether it returns the value for a MONDAY. Depending on the second parameter of the WEEKDAY function , the value used for checking will change.

        The default value for this second parameter is 1 , and this gives the weekdays from 1 through 7 , with 1 signifying Sunday , and 7 signifying Saturday ; thus , in this set , Monday would be 2.

        Now , we need to pass an array of dates to the WEEKDAY function ; this will be an array of dates from StartDate through EndDate , both dates inclusive.

        This we can do using the ROW function.

        Unfortunately , the ROW function acts on values , not on cell references ; thus , given the formula :

        =ROW(7:17)

        we get an array of values {7;8;9;10;11;12;13;14;15;16;17}.

        To get the same array of values using cell references , we would need to use :

        =ROW(A7:A17)

        Any other column reference can be used in place of column A e.g.

        =ROW(IX7:IX17)

        would return the same array of values from 7 through 17.

        The situation we have in our case is that the StartDate is in a cell reference B1 , and the EndDate is in another cell reference. Using these references directly , as in :

        =ROW(B1:B2)

        would only result in an array of two values {1;2} !

        Thus , to use the values of StartDate and EndDate through their cell references , one way would be to use the INDIRECT function ( there are other ways too ).

        The complication here is that the INDIRECT function takes in parameters which are strings ; hence we cannot use :

        =ROW(INDIRECT(B1:B2))

        To generate the string for the INDIRECT function , we use the CONCATENATE function , or its shortcut , the & symbol. Hence :

        =ROW(INDIRECT(B1 & “:” & B2))

        This generates an array of values from the StartDate through the EndDate , both dates inclusive.

        1. Hi Narayan,

          I have only just seen your reply to my question.

          Thank you for taking the time to explain this to me.

          I’m much clearer on how it works now.

          tnx

          Mark

  2. In DAX, assuming you have a Date table

    EVALUATE
    ROW (
    “Count of Mondays”, COUNTROWS (
    FILTER (
    DateTable,
    DateTable[Date] > DATEVALUE ( “2014-12-31” )
    && DateTable[Date] < TODAY ()
    && WEEKDAY ( DateTable[Date] ) = 2
    )
    )
    )

  3. Mine certainly isn’t the shortest formula, but is more intuitive for me to understand:
    =QUOTIENT((End-Start),7) + OR(WEEKDAY(Start)=2,WEEKDAY(End)=2)

    The second term covers the case where the start or the end date is on a Monday, which is needed to cover for partial weeks.

    1. Not working for periods less than 7 days…
      This should fix the problem:
      =INT((ED-SD+7)/7)-AND(WEEKDAY(SD,3)>0;WEEKDAY(ED,3)>0)

          1. @Gianluca,
            I was referring to your first(!) formula.
            (You posed a new and longer one WHILE I was typing my comments).
            The last one works OK – however, as there might be many sorts of formulas – I always look for shorter formulas.
            So far the:
            =SUMPRODUCT(N(WEEKDAY(ROW(INDIRECT(B1&”:”&B2)))=2))
            is the shortest that also works as expected.

          2. @Michael (reply to post below)
            Shorter then your shortest… (array formula)

            ={INT((ED-SD+7)/7)-AND(WEEKDAY(SD:ED,3)>0)}

  4. =IF(WEEKDAY(FIRSTDAY,11)=1,1,0)+INT(DAYS(LASTDAY,FIRSTDAY)/7)+IF(MOD(DAYS(LASTDAY,FIRSTDAY),7)+WEEKDAY(FIRSTDAY,11)>7,1,0)

    Where LASTDAY is assumed to be later or equal to FIRSTADAY.

    1. Let me give another solution.

      =ABS(INT((N(DAY_2)-2)/7)-INT((N(DAY_1)-2)/7))

      where DAY_1 and DAY_2 are two DIFFERENT dates.

  5. Function monday_count(date1 As Date, date2 As Date)
    Dim i As Long: Dim count As Long
    For i = date1 To date2
    If Weekday(i) = 2 Then count = count + 1
    Next i
    monday_count = count
    End Function

  6. =IF(AND(WEEKDAY(F15,1)=2,WEEKDAY(G15,1)=2),QUOTIENT((G15-1)-(F15+1),7)+2,IF(OR(WEEKDAY(F15,1)=2,WEEKDAY(G15,1)=2),QUOTIENT((G15-1)-(F15+1),7)+1,QUOTIENT((G15-F15),7)))

    Will return the number of Mondays.

    1. The above formula will return incorrect number of Mondays if the start date and end date are same..

      The following formula will return correct number of Mondays..

      =IF(AND(G15=F15,WEEKDAY(G15,1)=2),1,IF(G15>=F15,IF(AND(WEEKDAY(F15,1)=2,WEEKDAY(G15,1)=2),QUOTIENT((G15-1)-(F15+1),7)+2,IF(OR(WEEKDAY(F15,1)=2,WEEKDAY(G15,1)=2),QUOTIENT((G15-1)-(F15+1),7)+1,QUOTIENT((G15-F15),7))),”Start Date later than End Date”))

  7. Here is my try at this:
    ={SUM((E:E>=StartDate)*(E:E<=StopDate)*(WEEKDAY(E:E)=DayChosen)/DayChosen*(WEEKDAY(E:E)))}

    Where Col E contains dates
    StartDate & StopDates are input cells
    DayChosen is a dropdown list Sun, Mon, Tue,… which converts to 7,1,2,… based on day chosen

  8. Sorry for me VBA is easier to use across workbooks…

    Function HowManyMonday(datStart As Date, datEnd As Date)
    ‘ Returns the number of Mondays between two dates.
    Dim i As Long, j As Integer

    For i = datStart To datEnd

    j = j + Abs(Weekday(i, vbMonday) = 1)
    Next i
    HowManyMondays = j
    End Function

    In VBA Weekday(i, vbMonday) = 1 returns TRUE which equals -1 that is why ABS is used. A minus would do the same but more obscure.

    1. @Daniel,
      You have a slight TIPO in the Function’s Name.
      If I may suggest (especially for Maintenance & User Friendly reasons) the following UDF:
      Function HowManyMondays(datStart As Date, datEnd As Date, D As Integer)
      ‘ Returns the number of days “D” between two dates.
      Dim i As Long, j As Integer
      For i = datStart To datEnd
      HowManyMondays = HowManyMondays + Abs(Weekday(i, D) = 1)
      Next i
      End Function

        1. Function HowMany_D_Days(datStart As Date, datEnd As Date, D As Integer)
          ‘ Returns the number of days “D” between two dates.
          Dim i As Long, j As Integer
          For i = datStart To datEnd
          HowMany_D_Days = HowMany_D_Days + Abs(Weekday(i, D) = 1)
          Next i

  9. =IF(SD<=ED,INT(WEEKDAY(SD,12)/7)+ INT((ED-SD+WEEKDAY(SD,3))/7),"error -start date is after end date")

    Amazed at the variety of answers – my formula is a little bit wasteful. I am sure there is a simpler way, but I tested it and it works.

  10. #1 =SUMPRODUCT(–(TEXT(ROW(INDIRECT(SD&”:”&ED)),”DDDD”)=”Sunday”))
    But this formula is English.

    Turkish formula use “GGGG”
    =TOPLA.ÇARPIM(–(METNEÇEV?R(SATIR(DOLAYLI(SD&”:”&ED));”GGGG”)=”Pazartesi”))

    #2 =SD-ED+1-NETWORKDAYS.INTL(SD;ED;12)

  11. @Gianluca:
    As for your really short formula (posted December 19, 2015 at 12:40 am) Please check it against:
    SD = 01/01/2016
    ED = 28/09/2016
    It should return: 39 (not 38)

  12. Here’s mine:
    =((A2-WEEKDAY(A2,3))-(A1-WEEKDAY(A1, 3)))/7+IF(WEEKDAY(A1,3)=0,1,0)
    Using WEEKDAY(A1,3) gives you 0 for Monday, then subtracting the two and dividing by 7: ((A2-..)-(A1-..))/7 gives the number of Mondays, but not if the first date A1 is a Monday, so we have to add 1 in that case.

    BTW what is the advantage of using the function QUOTIENT instead of simply dividing?

  13. =ROUNDDOWN((((A2-A1+1)-CHOOSE(WEEKDAY(A1),1,0,6,5,4,3,2))/7)+1,0)

    START DATE – A1
    END DATE – A2

    S, M, T, W, T, F, S = 1, 0, 6, 5, 4, 3, 2

    Which day you want to count arrenge serial no. that way i.e. Monday = 0

  14. FREQUENCY(N(WEEKDAY(ROW(INDIRECT(A1&”:”&B1)),2)),1)
    if only for Mondays

    SUM(–(TEXT(ROW(INDIRECT(A1&”:”&B1)),”DDD”)=”Mon”))

  15. Hi
    INT(DATEDIF(SD+7-WEEKDAY(SD,3),ED,”d”))/7)+1

    Where Monday is the first day of the week.

    If SD=Monday and this Monday should be included, then ((Weekday, 3) =1)*1 +formula

    Have a good day.

  16. Guys,

    Why are you proposing complicated solutions?

    IMHO, the easiest way would be to get the floor of (the difference between SD, ED, and the adjustment to first Monday using Weekday) / 7.

    1. @mma173,
      As per your verbal explanation – would you be kind enough to present the actual FORMULA(!) that returns: 66 FRIDAYs for:
      SD = 01/01/2016
      ED = 31/03/2017
      Thanks.

      1. Without the Floor part, the formula should look something like:
        =((End Date-Start Date)+(7-(WEEKDAY(Start Date)-2)))/7+1

        I forgot to mention the (+1) required to include the first Monday.
        You can also simplify the adjustment part.

        Thanks’

        1. mma173,
          Sorry, but if you find it difficult to present a FULL FORMULA (without “look something like”) – I have nothing more to say.
          Thanks.

        2. @mma173,
          …by the way I presume that Chandoo’s basic meaning was that the requested formula should work as expected by counting all sort of weekdays (not only Mondays).

          1. The formula I presented is the full formula. I tried it and it works. Sorry for using the wrong English expression ????

            Moreover, it can be adjusted to count another day of the week.

    1. Thanks’ for your interest.
      The adjustment part was incorrect. Check this now:

      =(End Date – (Start Date + MOD((7-(WEEKDAY(Start Date)-Weekday(Monday),7)))/7+1

  17. Hi

    This macro pull all Mondays then cout
    Dim dStart As Date
    Dim dEnd As Date
    Dim rw As Integer

    dStart = Range(“A2”).Value
    dEnd = Range(“A3”).Value

    rw = 2
    While dStart < dEnd
    If Weekday(dStart) = vbMonday Then
    Cells(rw, 3).Value = dStart
    Cells(rw, 3).NumberFormat = "m/d/yyyy"
    rw = rw + 1
    End If
    dStart = dStart + 1
    Wend

    1. Oops! Didn’t read the instructions. Small adjustment added at the end of the above to deal with “(including the start & end dates)”

      QUOTIENT(End-Start+WEEKDAY(Start,3),7)+IF(WEEKDAY(Start,3)=0,1,0)

  18. a mathematical approach

    =INT((A2-A1+1)/7)+IF(AND(MOD((A2-A1+1),7)+WEEKDAY(A1,2)-1<=7,WEEKDAY(A1,2)1),0,1)

    start day a1
    end day a2

  19. Finished my homework.
    This formula can return the number of any weekday. The ‘daynumber’ in the formula can be hard-coded or a named range. Enter 1 for Sunday and 7 for Saturday
    This formula works.

    INT((DATEDIF (SD +7+”daynumber”-WEEKDAY(SD,17)-7*(WEEKDAY (SD, 17)<="daynumber "), ED,"d")) /7)+1

    Have a good day.

  20. =IF(OR(MOD(SD,7)=2,MOD(ED,7)=2),ROUNDDOWN((ED-SD)/7,0)+1,ROUNDDOWN((ED-SD)/7,0))

    This formula is based on simple division rule , considering the 0th date in excel falls on saturday , we need to add one to our count, if any of start date or End date falls on Monday.

    SD : Start Date
    ED : End Date

    1. =IF(F15>G15,”End Date must be later than start date”,IF(AND(F15=G15,WEEKDAY(F15,1)=2),1,IF(AND(WEEKDAY(F15,1)=2,WEEKDAY(G15,1)=2),QUOTIENT((G15-1)-(F15+1),7)+2,IF(OR(WEEKDAY(F15,1)=2,WEEKDAY(G15,1)=2),QUOTIENT((G15-1)-(F15+1),7)+1,QUOTIENT((G15-F15),7)))))

      This formula works for all situations.. even if start date is equal to end date

  21. = INT( (WEEKDAY(A1-2) + A2 – A1) / 7)

    where the cell A1 holds the start date and A2 holds the end date.

    This formula works correctly for all situations. It can be tweaked for any day of the week. It is very simple and elegant.

    In the expression (A1-2), 2 denotes Mon. Use 1 for Sun, 3 for Tue, 4 for Wed, 5 for Thu, 6 for Fri, 7 for Sat.

  22. What about this?

    =EndDate – StartDate – NETWORKDAYS.INTL(StartDate,EndDate,12) + 1

    where 12 means Mondays “are weekends”

    Gives me 8 for example of 01/12/2015 – 31/01/2016

    Shouldn’t this be the simplest formula to get the job done?

  23. =IF(D5E5,INT(IF(WEEKDAY(start)-_
    WEEKDAY(end)=0,wkdsum+1,wkdsum)),_
    INT(IF(WEEKDAY(start)-WEEKDAY(end)=0,wkdsum+1,wkdsum)-1))

    were wkdsum=IF(wkd>7,dsum/7-1,dsum/7)…
    dsum=(DAYS(end,start)+WEEKDAY(end))…
    wkd=E5+D5

  24. made a mistake…should read IF(WEEKDAY(start)WEEKDAY(end),INT(IF(WEEKDAY(start)-_
    WEEKDAY(end)=0,wkdsum+1,wkdsum)),_
    INT(IF(WEEKDAY(start)-WEEKDAY(end)=0,wkdsum+1,wkdsum)-1))

  25. there needs to be a “not equal” sign where the “***” is in the formula…IF(WEEKDAY(start)***WEEKDAY(end),INT(IF(WEEKDAY(start)-_

    no idea why char aren’t uploading…

  26. It seems that many answers include a variation of this:

    =SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A1&”:”&A2)))=2)*1)

    where the initial date is on A1 and the final date on A2

    1. This formula is neat. However, I prefer the ones based on simple division and small adjustment. The reason is that Sumproduct is less efficient; much more calculations (comparsions) are being done in the background.

  27. Adapting Mike Girvin’s formula to find the number of Friday 13ths between two dates, it can be simplified just to look for a weekday.

    =SUMPRODUCT(–(TEXT(ROW(INDIRECT(SD&”:”&ED)),”ddd”)=”Mon”))

  28. Sub HowManyMonday(startDate As Date, endDate As Date)

    Dim startDay As String

    If startDate > endDate Then Exit Sub
    startDay = VBA.Format(startDate, “ddd”)
    countMonday = VBA.Round((VBA.DateDiff(“d”, startDate, endDate) / 7), 0)
    If startDay = “Mon” Then countMonday = countMonday + 1 Else countMonday = countMonday
    MsgBox “There are ” & countMonday & ” Monday(s) between ” & startDate & ” and ” & endDate
    End Sub

  29. =ROUNDUP(DATEDIF(A1,B1,”D”)/7,0)+IF(AND(WEEKDAY(A1)=2,WEEKDAY(B1)=2),1,0)

    Here, Cell A1 = Start Date
    and Cell B1 = End Date

  30. =SUM((WEEKDAY((Start_Date+ROW(INDIRECT(“1:”&End_Date-Start_Date))-1),2)=1)*1)

    I live in country where Sunday is last day of week, so Monday = 1.

    1. Awesome! I was trying to manipulate NETWORKDAYS.INTL as well and
      came up with
      =(B1-A1)+1-NETWORKDAYS.INTL(A1,B1,12)

      But had no idea it took binary.

  31. This should work:

    =ROUNDUP((D8-IF(E7=5,D7+3,IF(E7=6,D7+2,IF(E7=7,E7+1,IF(E7=4,E7+4,IF(E7=3,D7+5,IF(D7=2,D7+6,D7)))))))/7,0)

  32. One more

    =INT((end-start+8-WEEKDAY(end,how_many))/7)

    where for
    how_many=11 : the number of Mondays is calculated
    how_many=12 : the number of Tuesdays is calculated

    how_many=17 : the number of Sundays is calculated

    However John Jairo Vs answer is excellent!!!!

  33. Why not

    =FLOOR( (A2-A1-WEEKDAY(A2,3)) / 7 ,1) + 1

    A1 = Start Date
    A2 = End Date

    or ignore date order

    =FLOOR( (ABS(A2-A1) – WEEKDAY( MAX(A2,A1) ,3)) /7 ,1) + 1

  34. =IF(WEEKDAY(Start_Date,2)>1,ROUNDDOWN(DAYS(End_Date,Start_Date)/7,0),ROUNDDOWN(DAYS(End_Date,Start_Date)/7,0)+1)

    Got this idea from the formula for “Reverse Coding” survey results.

    (Number of Choices-x)+1

      1. One more try…

        =IF(WEEKDAY(Start_Date,2)>1,
        ROUNDDOWN(DAYS(End_Date,Start_Date)/7,0),
        ROUNDDOWN(DAYS(End_Date,Start_Date)/7,0)+1)

  35. =SUMPRODUCT(1*(WEEKDAY(ROW(INDIRECT(A1&”:”&A2)))=2))

    Where Celll A1contains the start date and A2 contains the end date

  36. I think I’ve got q couple solns:

    =round(networksdays(start-weekday(start,3),end-weekday(end,3))/5,0)

    Or

    =round((end-weekday(end,3)-start-weekday(start,3)))/7,0)

    As in, the solution should be the number of weeks between the Monday of each week.

  37. Use CTRL + SHIFT + ENTER when using formula:

    =COUNT(IF(WEEKDAY(A:A)=2,A:A))

    Explanation
    – Column A has dates
    – Weekday formula turn dates into day number. 2 is Monday

  38. Function CountADayBetwen(StartDAte As Date, EndDate As Date, TheDay As String)

    Select Case TheDay

    Case “Sunday”
    Nday = 1

    Case “Monday”
    Nday = 2

    Case “Tuesday”
    Nday = 3

    Case “Wednesday”
    Nday = 4

    Case “Thursday”
    Nday = 5

    Case “Friday”
    Nday = 6

    Case “Saturday”
    Nday = 7

    End Select

    For i = StartDAte To EndDate

    If Weekday(i) = Nday Then
    x = x + 1
    End If

    Next

    CountADayBetwen = x

    End Function

  39. A2 = Start date; A3 = End date

    =IF(WEEKDAY(A2)=WEEKDAY(A3),ROUND(((A3-A2)/7)-0.14286,0)+1,ROUND(((A3-A2)/7)-0.14286,0))

  40. Man, this article it’s what I was looking for in the last couple weeks! Congratulations for this great text

  41. =INT((WEEKDAY(A1-2)-A1+A2)/7)
    just put starting date in cell A1 and end date in Cell B2.
    and change the day no in formula where -2 is a day no..
    Day no like {sun, mon, tue, wed, thu, fri, sun} {1,2,3,4,5,67}

  42. H8 = SUMPRODUCT(IF(WEEKDAY(ROW(INDIRECT(E8&”:”&F8)))=2,1,0))

    by putting starting date in E8 & ending date in F8

    CTRL+SHiFT+ENTER

    1. @GOPI?
      It should not, necessarily, be an “Array formula and the use of IF is also unnecessary.

      Try: =SUMPRODUCT(N(WEEKDAY(ROW(INDIRECT(E8&”:”&F8)))=2))

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.