Here is a VB 6 fuction I used to calculate number of hours worked given a start time and an end time (24 hour format). This function worked even when start time > end time (17:00 start time - 03:12 end time next morning). The result is formatted in tenths of an hour (ex. 10.2 hours worked).
I'm trying to update this function to work with MS Visual Studio 2010.
Any help would be greatly appreciated. Thanks.
Function CalculateDailyHours(InTime As String, OutTime As String) As String
Dim StartTime As Date
Dim EndTime As Date
Dim Temp As Date
Dim Minutes As Integer
' **************************************
StartTime = CDate(InTime)
EndTime = CDate(OutTime)
' **************************************
EndTime = DateAdd("d", 1, EndTime) ' Initialize a date
If StartTime > EndTime Then
EndTime = DateAdd("d", 1, EndTime) ' Add 24 hours if ST>ET
Temp = EndTime - Startime
Else
Temp = EndTime - StartTime
End If
' *************************************
Minutes = DatePart("n", Temp) * (5 / 3) ' Convert minutes to fraction
' *************************************
CalculateDailyHours = Format$(DatePart("h", Temp) + (Minutes / 100), "##.00")
End Function