G
Greg
I found the following function to calculate time difference. Everything
works great however I need to change minutes to decimal after final
calculation. I would like to change for ex 1 minute to .001, 2 minutes to
..003, 20 minutes to .024. How can I do that and where in a code i insert
additional code? I don't need to display seconds so I am not using this part
of the code Thanks
Public Function ElapsedTimeString(dateTimeStart As Date, _
dateTimeEnd As Date) _
As String
'*************************************************************
' Function ElapsedTimeString(dateTimeStart As Date,
' dateTimeEnd As Date) As String
' Returns the time elapsed between a starting Date/Time and
' an ending Date/Time formatted as a string that looks like
' this:
' "10 days, 20 hours, 30 minutes, 40 seconds".
'*************************************************************
Dim interval As Double, str As String, days As Variant
Dim hours As String, minutes As String, seconds As String
If IsNull(dateTimeStart) = True Or _
IsNull(dateTimeEnd) = True Then Exit Function
interval = dateTimeEnd - dateTimeStart
days = Fix(CSng(interval))
hours = Format(interval, "h")
minutes = Format(interval, "n")
seconds = Format(interval, "s")
' Days part of the string
str = IIf(days = 0, "", _
IIf(days = 1, days & " Day", days & " Days"))
str = str & IIf(days = 0, "", _
IIf(hours & minutes & seconds <> "000", ", ", " "))
' Hours part of the string
str = str & IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours"))
str = str & IIf(hours = "0", "", _
IIf(minutes & seconds <> "00", ", ", " "))
' Minutes part of the string
str = str & IIf(minutes = "0", "", _
IIf(minutes = "1", minutes & " Minute", _
minutes & " Minutes"))
str = str & IIf(minutes = "0", "", _
IIf(seconds <> "0", ", ", " "))
'Seconds part of the string
' str = str & IIf(seconds = "0", "", _
' IIf(seconds = "1", seconds & " Second", _
' seconds & " Seconds"))
ElapsedTimeString = IIf(str = "", "0", str)
End Function
works great however I need to change minutes to decimal after final
calculation. I would like to change for ex 1 minute to .001, 2 minutes to
..003, 20 minutes to .024. How can I do that and where in a code i insert
additional code? I don't need to display seconds so I am not using this part
of the code Thanks
Public Function ElapsedTimeString(dateTimeStart As Date, _
dateTimeEnd As Date) _
As String
'*************************************************************
' Function ElapsedTimeString(dateTimeStart As Date,
' dateTimeEnd As Date) As String
' Returns the time elapsed between a starting Date/Time and
' an ending Date/Time formatted as a string that looks like
' this:
' "10 days, 20 hours, 30 minutes, 40 seconds".
'*************************************************************
Dim interval As Double, str As String, days As Variant
Dim hours As String, minutes As String, seconds As String
If IsNull(dateTimeStart) = True Or _
IsNull(dateTimeEnd) = True Then Exit Function
interval = dateTimeEnd - dateTimeStart
days = Fix(CSng(interval))
hours = Format(interval, "h")
minutes = Format(interval, "n")
seconds = Format(interval, "s")
' Days part of the string
str = IIf(days = 0, "", _
IIf(days = 1, days & " Day", days & " Days"))
str = str & IIf(days = 0, "", _
IIf(hours & minutes & seconds <> "000", ", ", " "))
' Hours part of the string
str = str & IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours"))
str = str & IIf(hours = "0", "", _
IIf(minutes & seconds <> "00", ", ", " "))
' Minutes part of the string
str = str & IIf(minutes = "0", "", _
IIf(minutes = "1", minutes & " Minute", _
minutes & " Minutes"))
str = str & IIf(minutes = "0", "", _
IIf(seconds <> "0", ", ", " "))
'Seconds part of the string
' str = str & IIf(seconds = "0", "", _
' IIf(seconds = "1", seconds & " Second", _
' seconds & " Seconds"))
ElapsedTimeString = IIf(str = "", "0", str)
End Function