G Guest Oct 25, 2005 #1 I need to calculate the difference in a query between two time fields that are formatted
D Douglas J Steele Oct 25, 2005 #2 DateDiff only allows you to choose a single unit. The following function calculates the difference in minutes, then converts that value to hh:mm Function TimeDiff(Time1, Time2) As String Dim lngMinutes As Long lngMinutes = DateDiff("n", Time1, Time2) TimeDiff = Format(lngMinutes \ 60, "0") & ":" & _ Format(lngMinutes Mod 60, "00") End Function
DateDiff only allows you to choose a single unit. The following function calculates the difference in minutes, then converts that value to hh:mm Function TimeDiff(Time1, Time2) As String Dim lngMinutes As Long lngMinutes = DateDiff("n", Time1, Time2) TimeDiff = Format(lngMinutes \ 60, "0") & ":" & _ Format(lngMinutes Mod 60, "00") End Function