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

前端 未结 3 1829
抹茶落季
抹茶落季 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:20

    Try this.

    SELECT UID, switch (
    t>1 , '00:15' 
    ,true,format(t,'hh:mm')
    ) as Time_Elapsed from
    (
    SELECT UID, sum(Time_Elapsed) as t
    From Table1
    Group By UID
    )
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-12 08:29

    I hope, this SQL query helps:

    SELECT T.UID,
           CSTR(total_hours 
                    + INT(total_min / 60)) 
                    + ":" 
                    + CSTR(total_min Mod 60) as result
    FROM
        (SELECT UID,
                SUM(HOUR(TH.time_elapsed)) AS total_hours,
                SUM(MINUTE(TH.time_elapsed)) AS total_min
        FROM trans_hist AS TH
        GROUP BY UID) AS T
    
    0 讨论(0)
提交回复
热议问题