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
[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