sbowman wrote:
After i get the avg in seconds, how do i convert back to dd:hh:nn:ss?
Hi Shelley,
Using the ideas from the following thread:
http://groups.google.com/group/comp....09026f870fd8fd
I came up with the following revised query (barely tested):
SELECT Avg(DateDiff("s ",TicketOpen,Ti cketClose)) AS AvgSeconds,
SecondsToElapse dTime([AvgSeconds]) AS AvgDuration FROM tblHelpTickets;
AvgSeconds AvgDuration
181.5 00:00:03:01.50
using:
'-----Begin Module Code-------
Type ElapsedTime
Days As Integer
Hours As Integer
Minutes As Integer
Seconds As Double
End Type
Public Function FormatElapsedTi me(theTime As ElapsedTime) As String
FormatElapsedTi me = Format(theTime. Days, "00") & ":" &
Format(theTime. Hours, "00") & ":" & Format(theTime. Minutes, "00") & ":"
& Format(theTime. Seconds, "00.00")
End Function
Public Function SecondsToElapse dTime(dblSecond sElapsed As Double) As
String
Dim AnElapsedTime As ElapsedTime
AnElapsedTime.D ays = dblSecondsElaps ed \ (3600# * 24)
AnElapsedTime.H ours = (dblSecondsElap sed \ 3600) Mod 24
AnElapsedTime.M inutes = (dblSecondsElap sed \ 60) Mod 60
AnElapsedTime.S econds = dblSecondsElaps ed - 60 * Int(dblSecondsE lapsed
/ 60)
SecondsToElapse dTime = FormatElapsedTi me(AnElapsedTim e)
End Function
'-------End Module Code-------
But, from an ADH excerpt on MSDN:
"Test 6: use Mid$ rather than concatenation
The often overlooked Mid$ statement allows you to insert text
substrings into other text values. For example, if you used the
following code:
Dim strValue As String
strValue = "I like you"
Mid$(strValue, 3, 4) = "love"
Debug.Print strValue
strValue would contain "I love you" once you had finished. The
alternative would be to write code like this:
Dim strValue As String
strValue = "I like you"
strValue = Left$(strValue, 2) & "love" & Mid$(strValue, 7)
Debug.Print strValue
The first alternative is significantly faster than the second. In our
test case, either concatenating a series of X characters to build an
output string, or using the Mid$ statement to replace each character in
the output string with X, the faster version (using Mid$) took only 50
percent as long as the slower version. Of course, the relative timings
might change depending on the action you were taking. In general,
concatenation should be avoided in VBA. (See Test6a/b for the full test
procedures.)"
So the FormatElapsedTi me function should be changed, maybe using
something like
strTemp = "dd:hh:nn:ss.ss "
along with a few calls to the Mid$ function. I haven't tried this yet.
James A. Fortune
CD********@Fort uneJames.com