Calculate date overlap in days

Generic formula 

=MAX(MIN(end1,end2)-MAX(start1,start2)+1,0)

Related formulas 

Get days between dates

Explanation

To calculate the number of days that overlap in two date ranges, you can use basic date arithmetic, together with the the MIN and MAX functions.

In the example shown, the formula in D6 is:

=MAX(MIN(end,C6)-MAX(start,B6)+1,0)

How this formula works

Excel dates are just serial numbers, so you can calculate durations by subtracting the earlier date from the later date.

This is what happens at the core of the formula here:

MIN(end,C6)-MAX(start,B6)+1

Here are are simply subtracting an earlier date from a later date. To figure out what dates to use for each date range comparison, we use MIN to get the earliest end date, and MAX to get the latest end date.

We add 1 to the result to make sure we are counting "fence posts" and not "gaps between fence posts" (analogy from John Walkenbach from the Excel 2010 Bible).

Finally, we use the MAX function to trap negative values and return zero instead. Using MAX this way is a clever way to avoid using IF.

Calculate date overlap in days

Generic formula 

=MAX(MIN(end1,end2)-MAX(start1,start2)+1,0)

Related formulas 

Get days between dates

Explanation

To calculate the number of days that overlap in two date ranges, you can use basic date arithmetic, together with the the MIN and MAX functions.

In the example shown, the formula in D6 is:

=MAX(MIN(end,C6)-MAX(start,B6)+1,0)

How this formula works

Excel dates are just serial numbers, so you can calculate durations by subtracting the earlier date from the later date.

This is what happens at the core of the formula here:

MIN(end,C6)-MAX(start,B6)+1

Here are are simply subtracting an earlier date from a later date. To figure out what dates to use for each date range comparison, we use MIN to get the earliest end date, and MAX to get the latest end date.

We add 1 to the result to make sure we are counting "fence posts" and not "gaps between fence posts" (analogy from John Walkenbach from the Excel 2010 Bible).

Finally, we use the MAX function to trap negative values and return zero instead. Using MAX this way is a clever way to avoid using IF.