Help need formula for working out date overlaps

L

liztownsend

Hope someone can help, I'm looking for a formula to work out date overlaps.
e.g.
If my key dates are 1/11/08 to 30/11/08
I want to auto calculate how many days the following overlap with my key dates
01/01/08 to 31/12/08
16/11/08 to 05/12/08
etc

thanks!
 
R

Ron Rosenfeld

Hope someone can help, I'm looking for a formula to work out date overlaps.
e.g.
If my key dates are 1/11/08 to 30/11/08
I want to auto calculate how many days the following overlap with my key dates
01/01/08 to 31/12/08
16/11/08 to 05/12/08
etc

thanks!


=SUMPRODUCT(--ISNUMBER(MATCH(ROW(INDIRECT(A5&":"&B5)),ROW(INDIRECT(KeyDateStart&":"&KeyDateEnd)),0)))

Where your dates of interest are in A5 and B5
--ron
 
H

Herbert Seidenberg

The problem is that
1/11/08 to 30/11/08
when fully expanded reads:
1/11/08 12:00 AM to 30/11/08 12:00 AM
What we really want is:
1/11/08 00:00 to 30/11/08 24:00
which shortens to:
1/11/08 to 1/12/08
If we correct all the end dates this way and
remove all the +1's in Bob's formula, everything works.
Ron's formula now fails and it has problems
if we include odd times.
 
B

Bob Phillips

Not all of them, just one I think

=MAX(0,MIN(KeyDateEnd,$B2)-MAX(KeyDateStart,$A2))+1

Is Herbert Seidenberg and liztownsend one and the same?
 
B

Bob Phillips

Ron's is an array formula, but why use an array formula when you can do it
without.
 
R

Ron Rosenfeld

The problem is that
1/11/08 to 30/11/08
when fully expanded reads:
1/11/08 12:00 AM to 30/11/08 12:00 AM
What we really want is:
1/11/08 00:00 to 30/11/08 24:00
which shortens to:
1/11/08 to 1/12/08
If we correct all the end dates this way and
remove all the +1's in Bob's formula, everything works.
Ron's formula now fails and it has problems
if we include odd times.

Herbert,

My formula was not designed to handle anything other than full days, as
requested.

What are the circumstances under which it fails?
--ron
 
R

Ron Rosenfeld

I think your mind is far from simple Ron

--

Thank you.

I guess what I'm really trying to say is that different people think in
different ways. For me, in this kind of problem, it's easy for me to think in
terms of arrays. And even if it is not the most efficient algorithm for
solving the problem, unless the database is very large, it will likely be "good
enough" for now.

Your solution will certainly run faster, and will also not run into the dreaded
"5 Jun 2079" problem in pre-2007 versions, as would my solution :))
--ron
 
B

Bob Phillips

It was just a statement of fact by someone who reads your responses as a
matter of course because I know they will be enlightening. And my initial
comment wasn't meant as criticism of your formula, but more as extra
information for someone who joined in suggesting that an array formula might
do it, but didn't actually offer one.

As for 2079, I don't know about you, but I think it is beyond my realm of
needing to worry about <bg>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top