Time calculation/conversion problem
Hi all,
I have a problem with time conversion, I'm using this function, it works fine, the only problem is, I'm getting a result as a string (that was the only way I could write this - limited skills
). What I want to do is to have a result as integer, single, etc. as long as I could use this value for further calculations.
Public Function ElapsedHrs(DS As Date, TS As String, DE As Date, TE As String) As String
'Returns elapsed hrs with minutes
'DS = Start Date
'TS = Start Time in 24 hr (military) format hh:mm
'DE = End Date
'TE = End Time in 24 hr (military) format hh:mm
Dim dhrs As Single, ehrs As Single, tdays As Integer
'Calculate # of days
tdays = DateDiff("d", DS, DE) * 1440
'Calculate # of minutes
ehrs = DateDiff("n", TS, TE)
'Format # of days in minutes
dhrs = tdays / 60
'Calculate elapsed hours
ElapsedHrs = Int((ehrs + tdays) / 60) & " hr " & (ehrs + tdays) Mod 60 & " min"
End Function
Any help would be much appreciated.
Cheers
Mark
Hi all,
I have a problem with time conversion, I'm using this function, it works fine, the only problem is, I'm getting a result as a string (that was the only way I could write this - limited skills

Public Function ElapsedHrs(DS As Date, TS As String, DE As Date, TE As String) As String
'Returns elapsed hrs with minutes
'DS = Start Date
'TS = Start Time in 24 hr (military) format hh:mm
'DE = End Date
'TE = End Time in 24 hr (military) format hh:mm
Dim dhrs As Single, ehrs As Single, tdays As Integer
'Calculate # of days
tdays = DateDiff("d", DS, DE) * 1440
'Calculate # of minutes
ehrs = DateDiff("n", TS, TE)
'Format # of days in minutes
dhrs = tdays / 60
'Calculate elapsed hours
ElapsedHrs = Int((ehrs + tdays) / 60) & " hr " & (ehrs + tdays) Mod 60 & " min"
End Function
Any help would be much appreciated.
Cheers
Mark
Last edited: