Calculate Number of days between two Dates (Year wise)

hardeep.kanwar

Well-known Member
Joined
Aug 13, 2008
Messages
691
Hello Experts

Today, I stuck with a different problem, I need to calculate numbers of days between 2 dates and also calculate the gap of days in yrs also.

See the below example

Start Date

<tbody>
</tbody>
End Date

<tbody>
</tbody>
Total Gap No. Days

<tbody>
</tbody>
No of Gap (yr) 2016

<tbody>
</tbody>
No of Gap (yr) 2017

<tbody>
</tbody>
No of Gap (yr) 2018

<tbody>
</tbody>
Remarks

<tbody>
</tbody>
25-11-17

<tbody>
</tbody>
10-01-18

<tbody>
</tbody>
460360
If years are Differenent than show the Value in both Yrs

<tbody>
</tbody>
01-01-17

<tbody>
</tbody>
02-02-17

<tbody>
</tbody>
320
364

<tbody>
</tbody>
if years are same in both in Column than Value should be ZERO in other Yr.

<colgroup><col></colgroup><tbody>
</tbody>
01-01-16

<tbody>
</tbody>
06-06-16

<tbody>
</tbody>
157

<tbody>
</tbody>
15700
if years are same in both in Column than Value should be ZERO in other Yr.

<colgroup><col></colgroup><tbody>
</tbody>
01-01-16

<tbody>
</tbody>
06-06-18

<tbody>
</tbody>
887

<tbody>
</tbody>
365

<tbody>
</tbody>
365

<tbody>
</tbody>
157

<tbody>
</tbody>

<tbody>
</tbody>




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

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
If the example you posted your expected results?
If so, then either they don't look correct, or I am not understanding you.

- In the first row of data, shouldn't there be a value in the 2018 column (if not, then why)?
- In the second row, why is there no value in the 2017 column? Why is there one in the 2018 column when neither of those dates are in 2018?
 
Upvote 0

Excel 2010
ABCDEF
7StartEndTotal201620172018
801-01-1606-06-18888366365157
9
8b
Cell Formulas
RangeFormula
C8=B8-A8+1
D8=MAX(0,MIN($B8,EOMONTH(D7,11))-MAX($A8,D7)+1)
E8=MAX(0,MIN($B8,EOMONTH(E7,11))-MAX($A8,E7)+1)
F8=MAX(0,MIN($B8,EOMONTH(F7,11))-MAX($A8,F7)+1)
Named Ranges
NameRefers ToCells
Mon="0111111"


N.B. Ignore the defined name; it doesn't apply to this questions.

2016 etc are dates like 1-1-2016 formatted as Year
 
Last edited:
Upvote 0
Assuming that your table starts in cell A1, so row 2 is the first row of data and column C is your "Total Gap" column, here are the formulas I came up with:

Cell C2: =B2-A2
Cell D2: =MAX(MIN(B2,DATE(2016,12,31))-MAX(A2,DATE(2016,1,1)),0)
Cell E2: =MAX(MIN(B2,DATE(2017,12,31))-MAX(A2,DATE(2017,1,1)),0)
Cell F2: =MAX(MIN(B2,DATE(2018,12,31))-MAX(A2,DATE(2018,1,1)),0)

I am not sure if those gaps should be inclusive of the start date. If so, you may just need to add 1 to each calculation.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,316
Messages
6,124,225
Members
449,148
Latest member
sweetkt327

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