View Single Post
Old 11-23-2005, 09:51 AM   #2 (permalink)
Joel Egghead
Registered User
 
Join Date: Oct 2005
Posts: 5
Joel Egghead is on a distinguished road
Im not sure if you are using .net or vb6 but, in vb.net it’s a built in to the Date and time datatype. Other words a function like this would work:
Private Sub Time()
Dim StartTime As Date
Dim EndTime As Date
Dim TotalHours, TotalMin As Integer


StartTime = "11/22/05 17:00:00"
EndTime = "11/23/05 01:36:00"


If StartTime.Hour > EndTime.Hour Then
'IF Time.hour goes past 23:59 to next day 24 hours - start hour + Time spent in new day
TotalHours = (24 - StartTime.Hour) + EndTime.Hour
Else
TotalHours = EndTime.Hour - StartTime.Hour
End If

If StartTime.Minute > EndTime.Minute Then
'IF Time.minute goes past 60 min – start min + End Min
TotalMin = (60 - StartTime.Minute) + EndTime.Minute
'Since we already added the hour in the hour section we have to delete it here because it really wasn’t a full hour
TotalHours = TotalHours - 1
Else
TotalMin = EndTime.Minute - StartTime.Minute
End If
txtFullTime.Text = TotalHours & "hrs. & " & TotalMin & "min."
End Sub

Now you can add more to this to cover milliseconds as well but this would work for hours and minutes it also holds your days of the year.
Hope this helps
It’s been awhile since I programmed in vb6 but I’m thinking they to had the same date datatype.
Joel Egghead is offline   Reply With Quote