访问 2013 年总和时间值
Posted
技术标签:
【中文标题】访问 2013 年总和时间值【英文标题】:Access 2013 Sum time values 【发布时间】:2015-05-29 22:36:35 【问题描述】: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】:您只需将时间跨度相加:
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
【讨论】:
以上是关于访问 2013 年总和时间值的主要内容,如果未能解决你的问题,请参考以下文章