MS Access: Summing time greater than 24 hours in query restarts from 1 again

前端 未结 3 1830
抹茶落季
抹茶落季 2020-12-12 07:37

I have a table trans_hist in MS Access program where time is stored in short Date format \"HH:MM\" ex:

[![Image][1]][1]

Now I have created a query which tell

3条回答
  •  时光取名叫无心
    2020-12-12 08:21

    Use a function like this:

    Public Function FormatHourMinute( _
      ByVal datTime As Date, _
      Optional ByVal strSeparator As String = ":") _
      As String
    
    ' Returns count of days, hours and minutes of datTime
    ' converted to hours and minutes as a formatted string
    ' with an optional choice of time separator.
    '
    ' Example:
    '   datTime: #10:03# + #20:01#
    '   returns: 30:04
    '
    ' 2005-02-05. Cactus Data ApS, CPH.
    
      Dim strHour       As String
      Dim strMinute     As String
      Dim strHourMinute As String
    
      strHour = CStr(Fix(datTime) * 24 + Hour(datTime))
      ' Add leading zero to minute count when needed.
      strMinute = Right("0" & CStr(Minute(datTime)), 2)
      strHourMinute = strHour & strSeparator & strMinute
    
      FormatHourMinute = strHourMinute
    
    End Function
    

    and a simple query:

    Select 
        UID,
        FormatHourMinute(Sum([Time_Elapsed])) As TotalTime
    From
        trans_hist 
    Group By
        UID
    

提交回复
热议问题