How would I get Word to calculate time as in a time sheet, such as:
In Time 8:00AM
Out Time 12:30PM
Word would give me 4.5 from that...
Use the DateDiff function to get the difference. Since the function is
defined to return a Long (a large integer value) rather than a Single
or a Double, you can't use the "h" interval parameter if you need to
calculate fractions of an hour; you have to use the "n" parameter to
get minutes, and then compute hours:minutes from that number...
Sub demo()
Dim startTime As Date, endTime As Date
Dim diffHr As Long, diffMin As Long
startTime = CDate("8:00 am")
endTime = CDate("12:35 pm")
diffMin = Abs(DateDiff("n", startTime, endTime))
diffHr = Int(diffMin / 60) ' truncated to whole hours
diffMin = diffMin Mod 60 ' remaining minutes
MsgBox diffHr & ":" & diffMin
End Sub