Home > Blockchain >  Excel count days per month between two dates using both months and years
Excel count days per month between two dates using both months and years

Time:12-21

I would like to know how to calculate days of each month between two dates:

A B C D E F G
1 From To 01/12/20 01/01/21 01/02/21 01/03/21 01/04/21
:-- :---------: :-----: :---------: :--------: :--------: :--------: :-------:
2 15/12/20 12/3/21 17 31 28 12 0

I have tried using a formula I found elsewhere on this website but it only picks up the relevant months from the column headers in row 1. I need it to pick up the years as well. I wonder if anyone is able to alter this formula to include years as well:

=SUMPRODUCT(--(MONTH(ROW(INDIRECT($A2 & ":" & IF($B2="",TODAY(),$B2))))=MONTH(C1)))

Note: Row 1 Dates are dates and not text.

Charles

CodePudding user response:

Try:

C2: =MAX(MIN(EOMONTH(C$1,0),$B2)-MAX(C$1,$A2) 1,0)

and fill across (and down) as needed.

enter image description here

  • Related