Robert Crandal wrote on 12/28/2010 :
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?
I hope that makes sense. I'm just looking for code to
do the calculation.
Thank you!
Robert
If you subtract the times from each other you will know elapsed time.
If you subtract the dates from each other you will know elapsed days.
Where you will have issue is when the time in B1 is <= the time in A1,
which indicates the elapsed time passed over midnight. In this case you
need to evaluate the two time values as well as the two date values to
accurately determine the elapsed time. Here's the scenarios you'll
encounter:
1. TimeA1 < TimeB1
2. TimeA1 = TimeB1
3. TimeA1 > TimeB1
Additionally, the date values will be one of these scenarios:
1. DateA2 = DateB2
2. DateA2 < DateB2
These only assume that ColA is the duration 'Start', and ColB is the
duration 'Stop'. The total time elapsed between 'Start' and 'Stop' must
factor both time and date values for each. So...
If(Start<Stop) AND DateStop=DateStart
Then (The duration occured on the same day)
CalculationLogic: Stop-Start*24 = Elapsed HH.MM
Example: Start=10:45AM, Stop=11:22PM:
ElapsedTime=12.62Hrs
If(Start=Stop) AND DateStop>DateStart
Then DateStop-DateStart*24 = Elapsed HH.MM
(The duration occured over more than 1 day)
Example: Start=12:00PM, Stop=12:00PM,
DateStart=12/28/2010, DateStop=12/29/2010:
ElapsedTime=24.00Hrs
If(Start>Stop) AND DateStop>DateStart
Then ((Stop+(DateStop-DateStart))-Start)*24 = Elapsed HH.MM
(The duration occured over more than 1 day)
Example: Start=9:00PM, Stop=1:00AM,
DateStart=12/28/2010, DateStop=12/29/2010:
ElapsedTime=4.00Hrs
This, of course, requires that time values are entered correctly for
AM/PM so that the time serials calculate correctly.