Access 2013 Sum time values

故事扮演 提交于 2019-12-13 01:28:42

问题


How to make a sum of time values in Access 2013?

My column looks like this: (thanks to @HansUp user!)

SELECT t.[Time From],
       t.[Time Until],
       Format((t.[Time Until] - t.[Time From]), 'h:nn') AS [Total],
       Format(#08:00# - (t.[Time Until] - t.[Time From]), 'h:nn') AS [Missing]
FROM tblVolkan AS t;

How can I make a sum of Missing without getting Error?


回答1:


You just sum the time spans:

SELECT 
    Sum([Time Until] - [Time From]) AS [SumTotal],
    Sum(#08:00# - ([Time Until] - [Time From])) AS [SumMissing]
FROM 
    tblVolkan;

If totals can exceed 24 hours, and you wish an hour:minute display, use the function below:

SELECT 
    FormatHourMinute(Sum([Time Until] - [Time From])) AS [SumTotal],
    FormatHourMinute(Sum(#08:00# - [Time Until] - [Time From])) AS [SumMissing]
FROM 
    tblVolkan;

-

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


来源:https://stackoverflow.com/questions/30540094/access-2013-sum-time-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!