Number of days of week between two date range by month

guilherme88

New Member
Joined
Aug 1, 2018
Messages
16
Hello,

I am looking to get the following result:
So basically I need to figure out how many turnaround( airplane comes in gets services and departs with another flight number to different destination) I have between two dates and week days.
For example:
Start End
20MAR20-28MAR20
Days of week
1___4_6_ (Monday, Thursday and Saturday) = 4 days (1monday,1Thursday and 2 Saturdays)

That means, between this period I will have 4 rotations
If my period is 27MAR20-20JUL20 for day _2_____(Tuesday) i know there are 16Tuesdays between these two dates, therefore for that given flight number I will have 16 rotations on Tuesdays for the given period. Now I am trying to figure out by month. Looking at the calendar I know March2020 has 1 Tuesday, April has 4, may has 4, june has 5, and July has 2=TTL16.

That is basically where I am trying to get I have created formulas to break down the days of week and the months in the period, now I need to figure out a way to know how many by month between the periods taking into account the days of the week in that period.


Also if my start date is 11feb20 and my end date is 11feb20 my day of week is D2(tuesday) this should return number 1 as there is only 1 tuesday between these two dates.

Really would appreciate some feeback.

Thank you very much

Guilherme
 

Book1
ABCDE
2Start DateEnd DateDay
327-03-202020-07-2020_2_____Mar1
4Apr4
5May4
6Jun5
7Jul2
8
9
10
11
Sheet1
Cell Formulas
RangeFormula
D3=IF(ROWS(D$3:D3)>(MONTH(B$3)-MONTH(A$3)+1),"",TEXT(EOMONTH(A$3,ROWS(D$3:D3)-1),"mmm"))
E3{=IF(D3="","",SUM(--ISNUMBER(MATCH(WEEKDAY(ROW(INDIRECT(IF(ROWS(E$3:E3)=1,A$3,EOMONTH(A$3,ROWS(E$3:E3)-2)+1)&":"&IF(TEXT(B$3,"mmm")=D3,B$3,EOMONTH(A$3,ROWS(E$3:E3)-1)))),11),(MID(SUBSTITUTE(C$3,"_",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(C$3,"_","")))),1)+0),0))))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
thank you but i couldnt understand how the formula works. what i am trying to get is to display the sums by month depending on month and year in the range
[TABLE="width: 794"]
<colgroup><col><col><col><col span="2"><col span="6"></colgroup><tbody>[TR]
[TD] Equip[/TD]
[TD]Station[/TD]
[TD] Frequency & Date[/TD]
[TD]from[/TD]
[TD]to[/TD]
[TD]Mar-20[/TD]
[TD]Apr-20[/TD]
[TD]May-20[/TD]
[TD]Jun-20[/TD]
[TD]Jul-20[/TD]
[TD]Aug-20[/TD]
[/TR]
[TR]
[TD]AT7[/TD]
[TD]ABZ[/TD]
[TD]1___567[/TD]
[TD="align: right"]27-Oct-19[/TD]
[TD="align: right"]28-Mar-20[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
ABCDE
Start DateEnd DateDay
_2_____

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]2[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]27-03-2020[/TD]
[TD="align: right"]20-07-2020[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] "]Mar[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] , align: right"]1[/TD]

[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] "]Apr[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] , align: right"]4[/TD]

[TD="align: center"]5[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] "]May[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] , align: right"]4[/TD]

[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] "]Jun[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] , align: right"]5[/TD]

[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] "]Jul[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=00B050]#00B050[/URL] , align: right"]2[/TD]

[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]D3[/TH]
[TD="align: left"]=IF(ROWS(D$3:D3)>(MONTH(B$3)-MONTH(A$3)+1),"",TEXT(EOMONTH(A$3,ROWS(D$3:D3)-1),"mmm"))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]E3[/TH]
[TD="align: left"]{=IF(D3="","",SUM(--ISNUMBER(MATCH(WEEKDAY(ROW(INDIRECT(IF(ROWS(E$3:E3)=1,A$3,EOMONTH(A$3,ROWS(E$3:E3)-2)+1)&":"&IF(TEXT(B$3,"mmm")=D3,B$3,EOMONTH(A$3,ROWS(E$3:E3)-1)))),11),(MID(SUBSTITUTE(C$3,"_",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(C$3,"_","")))),1)+0),0))))}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]
One last request Nishant

with different years in the dataset. i need to sum it by month and by origin (ABZ,BHX etc...) below a sample of the dataset.
If i want to display by month and year, would need the formula to be arranges in the following way:
OCT19 NOv19 DEC19 Jan20
ABZ 1 4
BHX 2 22 23 23


DATASET
[TABLE="width: 350"]
<colgroup><col><col><col span="2"></colgroup><tbody>[TR]
[TD]ABZ[/TD]
[TD]______7[/TD]
[TD="align: right"]27-Oct-19[/TD]
[TD="align: right"]27-Oct-19[/TD]
[/TR]
[TR]
[TD]ABZ[/TD]
[TD]___4___[/TD]
[TD="align: right"]31-Oct-19[/TD]
[TD="align: right"]26-Mar-20[/TD]
[/TR]
[TR]
[TD]BHX[/TD]
[TD]12__567[/TD]
[TD="align: right"]27-Oct-19[/TD]
[TD="align: right"]28-Mar-20[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]

How can this be achieved?

Thanks again
Guilherme
 
Upvote 0
thank you but i couldnt understand how the formula works. what i am trying to get is to display the sums by month depending on month and year in the range
[TABLE="width: 794"]
<tbody>[TR]
[TD]Equip[/TD]
[TD]Station[/TD]
[TD]Frequency & Date[/TD]
[TD]from[/TD]
[TD]to[/TD]
[TD]Mar-20[/TD]
[TD]Apr-20[/TD]
[TD]May-20[/TD]
[TD]Jun-20[/TD]
[TD]Jul-20[/TD]
[TD]Aug-20[/TD]
[/TR]
[TR]
[TD]AT7[/TD]
[TD]ABZ[/TD]
[TD]1___567[/TD]
[TD="align: right"]27-Oct-19[/TD]
[TD="align: right"]28-Mar-20[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]



Book1
ABCDEFGHIJK
15EquipStationFrequency & DatefromtoMar-20Apr-20May-20Jun-20Jul-20Aug-20
16AT7ABZ1___56727-Oct-1928-Mar-2016
17AT7ABZ1______27-Oct-1924-May-20543
Sheet1
Cell Formulas
RangeFormula
F16{=IF(F$15="","",IF(SUM(--ISNUMBER(MATCH(ROW(INDIRECT((EOMONTH(F$15,-1)+1)&":"&EOMONTH(F$15,0))),ROW(INDIRECT($D16&":"&$E16)),0)))>0,SUM(--ISNUMBER(MATCH(WEEKDAY(ROW(INDIRECT(MAX($D16,F$15)&":"&MIN($E16,EOMONTH(F$15,0)))),11),(MID(SUBSTITUTE($C16,"_",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE($C16,"_","")))),1)+0),0))),""))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0
One last request Nishant

with different years in the dataset. i need to sum it by month and by origin (ABZ,BHX etc...) below a sample of the dataset.
If i want to display by month and year, would need the formula to be arranges in the following way:
OCT19 NOv19 DEC19 Jan20
ABZ 1 4
BHX 2 22 23 23


DATASET
[TABLE="width: 350"]
<tbody>[TR]
[TD]ABZ[/TD]
[TD]______7[/TD]
[TD="align: right"]27-Oct-19[/TD]
[TD="align: right"]27-Oct-19[/TD]
[/TR]
[TR]
[TD]ABZ[/TD]
[TD]___4___[/TD]
[TD="align: right"]31-Oct-19[/TD]
[TD="align: right"]26-Mar-20[/TD]
[/TR]
[TR]
[TD]BHX[/TD]
[TD]12__567[/TD]
[TD="align: right"]27-Oct-19[/TD]
[TD="align: right"]28-Mar-20[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]

How can this be achieved?

Thanks again
Guilherme


Using VBA:


Book1
ABCDE
1DATASET
2ABZ______727.10.201927.10.2019
3ABZ___4___31.10.201926.03.2020
4BHX12__56727.10.201928.03.2020
5
6
7
8
9
10Oct-19Nov-19Dec-19Jan-20
11ABZ2445
12BHX3222321
13
Sheet3
Cell Formulas
RangeFormula
B11=SumDate($A$2:$D$4,$A11,B$10)


VBA Code:

Code:
Function SumDate(rng As Range, st As Range, cr_month As Date)


Dim arr As Variant
Dim i As Integer, d As Long
Dim tday As String, testch As String
Dim tempsum As Integer
Dim Strtdate As Date
Dim Enddate As Date
Dim datearr(1 To 31) As Variant
Dim check As Integer
Dim y As Integer


arr = rng.Value
tempsum = 0
x = 1


For d = cr_month To Application.WorksheetFunction.EoMonth(cr_month, 0)
    datearr(x) = d
    x = x + 1
Next d


i = 0
x = 0


For x = 1 To UBound(arr, 1)
    
    If arr(x, 1) = st Then
        
        For y = 1 To UBound(datearr, 1)
            If datearr(y) >= arr(x, 3) And datearr(y) <= arr(x, 4) Then
                check = check + 1
            End If
        Next y
                
        If check > 0 Then
            tday = arr(x, 2)
            
            For i = 1 To Len(tday)
                testch = Mid(tday, i, 1)
                If testch = "_" Then
                    Mid(tday, i, 1) = "1"
                ElseIf IsNumeric(testch) Then
                    Mid(tday, i, 1) = "0"
                End If
            Next i
                
            Strtdate = Application.WorksheetFunction.Max(arr(x, 3), cr_month)
            Enddate = Application.WorksheetFunction.Min(arr(x, 4), Application.WorksheetFunction.EoMonth(cr_month, 0))
            tempsum = tempsum + Application.WorksheetFunction.NetworkDays_Intl(Strtdate, Enddate, tday)
        
            check = 0
            
        End If
        
    End If


Next x


SumDate = tempsum


End Function
 
Last edited:
Upvote 0
Notes
1. A variety of formula solutions for your consideration.
2. D1 - M1 are dates such as September 30, 2019 formated at mmm-yy
3. A7 cell is Text.




Excel 2010
ABCDEFGHIJKLM
1DATASETSep-19Oct-19Nov-19Dec-19Jan-20Feb-20Mar-20Apr-20May-20Jun-20
2ABZSun27-Oct-1927-Oct-191
3ABZThu31-Oct-1926-Jun-20144544544
4Thu31-Oct-1926-Jun-20144544544
5BHXM,Tue,F,Sa,Su27-Oct-1928-Mar-2032223212120
6M,Tue,F,Sa,Su27-Oct-1928-Mar-2032223212120
70011000M,Tue,F,Sa,Su27-Oct-1928-Mar-2032223212120
8
1cc
Cell Formulas
RangeFormula
F3=NETWORKDAYS.INTL(E1+1,F1,"1110111")
E2=NETWORKDAYS.INTL(C2,D2,"1111110")
E3=NETWORKDAYS.INTL(C3,E1,"1110111")
E4=NETWORKDAYS.INTL(MAX(D1+1,$C$4),MIN($D$4,E1),"1110111")
E5=NETWORKDAYS.INTL(MAX(D1+1,$C$5),MIN($D$5,E1),"0011000")
E6=NETWORKDAYS.INTL(MAX(D$1+1,$C6),MIN($D6,E$1),Days5)
E7=NETWORKDAYS.INTL(MAX(D$1+1,$C7),MIN($D7,E$1),$A$7)
Named Ranges
NameRefers ToCells
Days5="0011000"
 
Upvote 0
Hi Nishant i have added another if to the formula and came to conclusion it is not reading the data correctly.
I want to cvount only the 00:25 turns so i put an if with the 00:25 in the formula. ABOVE THE COLUMNS corresponding to line 12. Thank you in advance

The formula is: IF([@Ground]=0.0173611111111111,IF(DC$5="","",IF(SUM(--ISNUMBER(MATCH(ROW(INDIRECT((EOMONTH(DC$5,-1)+1)&":"&EOMONTH(DC$5,0))),ROW(INDIRECT($I12&":"&$J12)),0)))>0,SUM(--ISNUMBER(MATCH(WEEKDAY(ROW(INDIRECT(MAX($I12,DC$5)&":"&MIN($J12,EOMONTH(DC$5,0)))),11),(MID(SUBSTITUTE($H12,"_",""),ROW(INDIRECT("1:"&LEN(SUBSTITUTE($H12,"_","")))),1)+0),0))),"")),"") +ctrlshiftenter


A B C D E F G H I J K DA DB DC[TABLE="width: 982"]
<tbody>[TR]
[TD="width: 60"] Equip[/TD]
[TD="width: 66"]Station[/TD]
[TD="width: 76"] Through[/TD]
[TD="width: 77"]Column1[/TD]
[TD="width: 66"]Arrives[/TD]
[TD="width: 70"]Departs[/TD]
[TD="width: 69"]Ground[/TD]
[TD="width: 142"] Frequency & Date[/TD]
[TD="width: 71"]from[/TD]
[TD="width: 71"]to[/TD]
[TD="class: xl70, width: 22"]Helper1[/TD]
[TD="class: xl67, width: 64"]Oct-19[/TD]
[TD="class: xl67, width: 64"]Nov-19[/TD]
[TD="class: xl67, width: 64"]Dec-19[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 982"]
<tbody>[TR]
[TD="width: 60"]AT7[/TD]
[TD="width: 66"]ABZ[/TD]
[TD="width: 76, align: right"]3242[/TD]
[TD="width: 77, align: right"]3243[/TD]
[TD="class: xl65, width: 66, align: right"]15:05[/TD]
[TD="class: xl65, width: 70, align: right"]15:30[/TD]
[TD="class: xl65, width: 69, align: right"]00:25[/TD]
[TD="width: 142"]__3____[/TD]
[TD="class: xl66, width: 71, align: right"]30-Oct-19[/TD]
[TD="class: xl66, width: 71, align: right"]18-Dec-19[/TD]
[TD="class: xl72, width: 22"][/TD]
[TD="width: 64, align: right"]1[/TD]
[TD="width: 64, align: right"] 5[/TD]
[TD="width: 64, align: right"]8[/TD]
[/TR]
</tbody>[/TABLE]
result shoud be: 1 4 3


Krgrds
Guilherme
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,714
Members
452,995
Latest member
isldboy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top