访问2013年总和时间值

时间:2015-05-29 22:36:36

标签: ms-access ms-access-2013

如何在Access 2013中创建时间总和?

我的专栏如下:(感谢@HansUp用户!)

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;

如何在不收到错误的情况下总结Missing?

1 个答案:

答案 0 :(得分:0)

您只需计算时间跨度:

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

如果总数超过24小时,并且您希望一小时:分钟显示,请使用以下功能:

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