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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
EquipStation Frequency & DatefromtoMar-20Apr-20May-20Jun-20Jul-20Aug-20
AT7ABZ1___56727-Oct-1928-Mar-20

<colgroup><col><col><col><col span="2"><col span="6"></colgroup><tbody>
</tbody>
 
Upvote 0
ABCDE
2Start DateEnd DateDay
327-03-202020-07-2020_2_____Mar1
4Apr4
5May4
6Jun5
7Jul2
8
9
10
11

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
D3=IF(ROWS(D$3:D3)>(MONTH(B$3)-MONTH(A$3)+1),"",TEXT(EOMONTH(A$3,ROWS(D$3:D3)-1),"mmm"))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
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))))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
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
ABZ______727-Oct-1927-Oct-19
ABZ___4___31-Oct-1926-Mar-20
BHX12__56727-Oct-1928-Mar-20
0

<colgroup><col><col><col span="2"></colgroup><tbody>
</tbody>

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
EquipStationFrequency & DatefromtoMar-20Apr-20May-20Jun-20Jul-20Aug-20
AT7ABZ1___56727-Oct-1928-Mar-20

<tbody>
</tbody>



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
ABZ______727-Oct-1927-Oct-19
ABZ___4___31-Oct-1926-Mar-20
BHX12__56727-Oct-1928-Mar-20
0

<tbody>
</tbody>

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
EquipStation ThroughColumn1ArrivesDepartsGround Frequency & DatefromtoHelper1Oct-19Nov-19Dec-19

<tbody>
</tbody>
AT7ABZ3242324315:0515:3000:25__3____30-Oct-1918-Dec-191 58

<tbody>
</tbody>
result shoud be: 1 4 3


Krgrds
Guilherme
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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