View Single Post
  #17   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default Complicated Time Formula

After having a very big think about your problem, it's much more complicated
than I first thought.

You have a start and end checking time range, call them cS, cE
You also have a start and end event time range, call them eS, eE

Consider also that an event may start before midnight and end after
midnight, but you are not dealing with dates. So it would appear the event
finished before it ended. eg. 23:30 to 02:30.

I've detected the following combinations in which the times may be ordered,
along with the outcome:
eS, eE, cS, cE = 0
eE, eS, cS, cE = cE-cS
eS, cS, eE, cE = eE-cS
eE, cS, eS, cE = cE-eS
eS, cS, cE, eE = cE-cS
eE, cS, cE, eS = 0
cS, eS, eE, cE = eE-eS
cS, eE, eS, cE = eE-cS + cE-eS
cS, eS, cE, eE = cE-eS
cS, eE, cE, eS = eE-cS
cS, cE, eS, eE = 0
cS, cE, eE, eS = cE-cS

So your formula for the first line could look like: if eS < eE and eE < cS
and cS < cE then 0, else.....
There's also opportunity to simplify since some of the outcomes are the same
(eg. = 0)

Hope this helps,

Rob



"Jay" wrote in message
...
One Problem down, one to go. The formula has trouble with
anytime around midnight. I get a negative number. Any
suggestions.

Thanks for your help
Jay