[AccessD] Tip: Sum elapsed time and display as a time string

A.D.Tejpal adtp at airtelmail.in
Thu Feb 5 23:00:05 CST 2009


Gustav,

    That is a nice one!  Thanks for kindly sharing with us.

    Equivalent UDF, using multiplication by 24 in lieu of DaeDiff(), could be:
'===============================
Function Fn_TotElapsedTimeFormatted( _
            TotElapsedTime As Single) As String
    ' Returns equivalent string in hh:nn:ss format
    ' TotElapsedTime is the sum of subtraction 
    ' between DateTime type values.
    Fn_TotElapsedTimeFormatted = _
                    Int(TotElapsedTime * 24) & _
                    Format(TotElapsedTime, ":nn:ss")
End Function
'===============================

Best wishes,
A.D. Tejpal
------------

  ----- Original Message ----- 
  From: Gustav Brock 
  To: accessd at databaseadvisors.com 
  Sent: Wednesday, February 04, 2009 12:57
  Subject: [AccessD] Tip: Sum elapsed time and display as a time string


  Hi all

  Did you know how easy it is in a query to sum elapsed time (of date/time value) and format this as a string even when count of hours exceed 24?

  SELECT 
      DateDiff("h",0,Sum([ElapsedTime])) & 
      Format(Sum([ElapsedTime]),":nn:ss") AS 
    ElapsedTimeTotal
  FROM 
    tblElapsedTime;

  This will return a string like, say, 45:37:12.

  The trick is, of course, to count the hours from date/time value 0 (zero). Then let Format handle the minutes and seconds.

  /gustav



More information about the AccessD mailing list