View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default Calculate if 2 times differ by 24 hours?

On Dec 27, 11:08*pm, "Robert Crandal" wrote:
So, cell A1 contains a fixed time in the format of "hh:mm:ss",
and cell A2 contains a fixed data in the format of "mm/dd/yy".
Users will be entering a time into cell B1 and a date into cell B2.

How can I determine if the times and dates entered into
cells B1 and B2 are greater than the fixed time and date
in cell A1 and A2 by more than 24 hours?


Ostensibly:

=IF(ABS(A1+A2-B1-B2)1,"24 hr","<=24 hr")

However, because time is stored as a fraction of a day and because
seconds are a very small fraction, you might run afoul of artifacts of
computer binary arithmetic, resulting in either a false positive or a
false negative.

The following will avoid that:

=IF(ROUND(ABS(A1+A2-B1-B2)*86400,0)86400,"24 hr","<=24 hr")

86400 is the number of seconds in a day.

Dates are stored as integers, namely the number of days since
12/31/1899 normally.

Time is stored as a fraction of a day. So A1+A2 is effectively the m/
d/yyyy h:mm:ss. Likewise for B1+B2.