Forum Discussion
Why is my If statement not working?
dfolk13 Explanation: Times in Excel are stored as the fraction of one day that they represent. 12:45 PM is (exactly) 0.53125 of a day; 2:45 PM is 0.614583333… of a day. But most real numbers (most numbers that include a fractional or "decimal" portion) cannot be exactly represented in a finite amount of computer memory.
Excel represents (essentially) all numbers as floating point; but Floating-point arithmetic may give inaccurate results in Excel. In this case, the subtraction apparently results in an internal value that is very slightly more than the 0.083333333… which represents two hours, so the equality test (actually, the <= test) that you expected to result in True did not.
Jan's formula does not include any equality tests. That formula seems to work. If some edge case(s) were found where it fails, you might just subtract one millisecond (e.g.) from the time difference (column C value) in that formula.