Number of days per quarter between 2 dates

dunDaan

New Member
Joined
Dec 12, 2018
Messages
3
Can someone help me to calculate the number of days per quarter between 2 dates?

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Start date[/TD]
[TD]End date[/TD]
[TD]Q1[/TD]
[TD]Q2[/TD]
[TD]Q3[/TD]
[TD]Q4[/TD]
[/TR]
[TR]
[TD]01 jan 2019[/TD]
[TD]30 jun 2019[/TD]
[TD]89[/TD]
[TD]91[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]01 feb 2019[/TD]
[TD]01 mar 2019[/TD]
[TD]28[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]01 feb 2019[/TD]
[TD]01 aug 2019[/TD]
[TD]58[/TD]
[TD]91[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]01 nov 2018[/TD]
[TD]01 aug 2019[/TD]
[TD]150[/TD]
[TD]-150[/TD]
[TD]0[/TD]
[TD]60[/TD]
[/TR]
[TR]
[TD]01 jul 2019[/TD]
[TD]31 dec 2019[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]91[/TD]
[TD]92[/TD]
[/TR]
</tbody>[/TABLE]

I'm currently using following formula's:

For Q1: =MIN(MAX(DATE(YEAR(A2),4,0)-A2,0),B2-A2)
For Q2: =MIN(MAX(DATE(YEAR(A2),7,0)-A2,0),B2-A2)-C2
For Q3: =MIN(MAX(DATE(YEAR(A2),10,0)-A2,0),B2-A2)-SUM(C2:D2)
For Q4: =MIN(MAX(DATE(YEAR(A2),13,0)-A2,0),B2-A2)-SUM(C2:E2)

This returns the values as seen in table above so it works quite well, however as you can see this is not working OK when the dates are not within the same year. (see 5th row)

Any suggestions to make this work for all possible dates? It is expected that end date > start date, so no need to account for end date < start date

Thanks in advance.

/dunDaan
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
however as you can see this is not working OK when the dates are not within the same year. (see 5th row)

Hi, welcome to the forum!

You didn't tell us what results you expect for the 5th row - but assuming you want to disregard the year and apportion all of the days into their respective quarter here is an option you can try (formula in C2 copied down and across).


Excel 2013/2016
ABCDEF
1Start dateEnd dateQ1Q2Q3Q4
201/01/201930/06/2019899100
301/02/201901/03/201928000
401/02/201901/08/20195891320
501/11/201801/08/201990913260
601/07/201931/12/2019009192
701/01/201831/12/2019179182184184
Sheet1
Cell Formulas
RangeFormula
C2=SUMPRODUCT(0+("Q"&ROUNDUP(MONTH(ROW(INDIRECT($A2+1&":"&$B2)))/3,0)=C$1))
 
Last edited:
Upvote 0
Thanks for the fast response FormR.

Indeed I wasn't completely clear in what the intended values should be.
The intention is that the cells in columns C through F show how many days each quarter has, based on the start date and end date indicated in columns A end B for a specific year (in this case 2019).

Knowing that the interval between start date and end date will not exceed 1 year, your solution works perfectly, thanks a lot!!
I will now dig in trying to understand what the formula actually does :stickouttounge:
 
Upvote 0
FormR, very elegant! The approach wasn't obvious, so it was a learning experience. Thanks
 
Last edited:
Upvote 0
for a specific year

Hi, in that case, this approach might be better (more efficient). In this example the specific year is stored in cell C1.


Excel 2013/2016
ABCDEF
12019
2
3Start dateEnd dateQ1Q2Q3Q4
401/01/201930/06/2019899100
501/02/201901/03/201928000
601/02/201901/08/20195891320
701/11/201801/08/20199091320
801/07/201931/12/2019009192
920/12/201830/04/202090919292
Sheet1
Cell Formulas
RangeFormula
C4=MAX(0,MIN($B4,DATE($C$1,1+(COLUMNS($C4:C4)*3),0))-MAX($A4,DATE($C$1,1+((COLUMNS($C4:C4)-1)*3),0)))
 
Upvote 0
Technically you're right, but for my purpose it doesn't really matter whether or not the first day is included.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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