(((1+ TimeValue(dtmend) - TimeValue(dtmstart))*1440) Mod 1440)/1440
AFAIK, this should work as long as the difference between Start and End is <
24 hours.
- TimeValue() strips any date information from the argument.
- Time is the decimal portion of a number where 1 = one day: 0.0 = midnight;
0.5 = 12 noon; 0.75 = 6 pm; etc
- 1440 is the number of minutes in a day
- Adding 1 to EndTime adds a full day to the value, ensuring it is always
"greater" than start time (this addresses midnight wrapping issues)
- Mod returns the remainder after division
*VBA's Mod converts arguments to whole numbers before it does division,
so we need to convert our decimal time values first to get accurate results
*The result of our Mod statement gives us the # of hours difference
regardless of midnight wrapping (because it removes the day info we added).
- Convert that whole number back to a time decimal. Format as desired.
(FWIW, this isn't as convoluted in an Excel worksheet because the Mod
worksheet function doesn't convert arguments to integers before division)
=Mod(End-Start,1)
HTH,