How many days in each month

daverubio

New Member
Joined
Mar 21, 2019
Messages
4
Context:

We have a check in date and a check out date. In order to reconcile every month, we need to see how many days for each booking get accounted to every month. So if a booking starts on jan 15 and end on Feb 4, we need to be able to report the 17 days booked in Jan and the 3 nights if Feb.

So, if I have:

a cell with one date and a cell with another, how can I show how many days in each month within that range?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Excel 2010
ABCDEF
1
2StartEndtotalJan-19Feb-19Mar-19
315-Jan-1904-Feb-19211740
4
5
6D2 etc1-Jan-19
7
3b
Cell Formulas
RangeFormula
C3=B3-A3+1
D3=MAX(0, MIN(EOMONTH(D$2, 0), $B3) + 1 - MAX(D$2, $A3))
E3=MAX(0, MIN(EOMONTH(E$2, 0), $B3) + 1 - MAX(E$2, $A3))
F3=MAX(0, MIN(EOMONTH(F$2, 0), $B3) + 1 - MAX(F$2, $A3))
 
Upvote 0
Thanks so much!!




Excel 2010
ABCDEF

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

[TD="align: center"]2[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F3F3F3]#F3F3F3[/URL] , align: center"]Start[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F3F3F3]#F3F3F3[/URL] , align: center"]End[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=F3F3F3]#F3F3F3[/URL] , align: center"]total[/TD]
[TD="align: center"]Jan-19[/TD]
[TD="align: center"]Feb-19[/TD]
[TD="align: center"]Mar-19[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]15-Jan-19[/TD]
[TD="align: right"]04-Feb-19[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=E5E5E5]#E5E5E5[/URL] , align: right"]21[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=E5E5E5]#E5E5E5[/URL] , align: right"]17[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=E5E5E5]#E5E5E5[/URL] , align: right"]4[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=E5E5E5]#E5E5E5[/URL] , align: right"]0[/TD]

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

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

[TD="align: center"]6[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CCCCFF]#CCCCFF[/URL] , align: right"]D2 etc[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CCCCFF]#CCCCFF[/URL] , align: right"]1-Jan-19[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=CCCCFF]#CCCCFF[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

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

</tbody>
3b

[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] "]C3[/TH]
[TD="align: left"]=B3-A3+1[/TD]
[/TR]
[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"]=MAX(0, MIN(EOMONTH(D$2, 0), $B3) + 1 - MAX(D$2, $A3))[/TD]
[/TR]
[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"]=MAX(0, MIN(EOMONTH(E$2, 0), $B3) + 1 - MAX(E$2, $A3))[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]F3[/TH]
[TD="align: left"]=MAX(0, MIN(EOMONTH(F$2, 0), $B3) + 1 - MAX(F$2, $A3))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Thanks so much again!

I ended up going with this formula:

=iferror(if(IF(OR(MONTH($H841)>MONTH(AK$1),MONTH($M841)<MONTH(AK$1)),0,MIN($M841,DATE(YEAR(AK$1),MONTH(AK$1)+1,0))-MAX($H841,AK$1)+1)<0,"0",IF(OR(MONTH($H841)>MONTH(AK$1),MONTH($M841)<MONTH(AK$1)),0,MIN($M841,DATE(YEAR(AK$1),MONTH(AK$1)+1,0))-MAX($H841,AK$1)+1)),"")

H841 is the arrival date
M841 is the departure date
AK$1 is the date for reference of the month (12/1/2019)


All went very well and it works like a dream. UNITL... there was a booking that started on December 28th and ended on January 2. This means that the logic pulling for month breaks. For that particular booking, it is not pulling. I'm assuming because it sees the month "1" is less than the month of the AK$1 entry.

Make sense?
 
Upvote 0

Excel 2010
ABCDEFG
1
2StartEndTotalDec-18Jan-19Feb-19Mar-19
328-Dec-1802-Jan-196420
428-Dec-1802-Jan-196420
515-Jan-1904-Feb-19210174
6
7D2 etc1-Dec-18
3b
Cell Formulas
RangeFormula
C3=B3-A3+1
C4=B4-A4+1
C5=B5-A5+1
D3=MAX(0, MIN(EOMONTH(D$2, 0), $B3) + 1 - MAX(D$2, $A3))
D4=MAX(0, MIN(E$2-1, $B4) + 1 - MAX(D$2, $A4))
D5=MAX(0, MIN(E$2-1, $B5) + 1 - MAX(D$2, $A5))
E3=MAX(0, MIN(EOMONTH(E$2, 0), $B3) + 1 - MAX(E$2, $A3))
E4=MAX(0, MIN(F$2-1, $B4) + 1 - MAX(E$2, $A4))
E5=MAX(0, MIN(F$2-1, $B5) + 1 - MAX(E$2, $A5))
F3=MAX(0, MIN(EOMONTH(F$2, 0), $B3) + 1 - MAX(F$2, $A3))
F4=MAX(0, MIN(G$2-1, $B4) + 1 - MAX(F$2, $A4))
F5=MAX(0, MIN(G$2-1, $B5) + 1 - MAX(F$2, $A5))
B7=D2
 
Upvote 0
Thanks for the feedback.
The suggestion is just 2 similar versions of post #2 .
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

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