我在Access中有一个字段,该字段采用两个时间值之间的日期差来确定总路线时间。现在,我需要将该字段中的所有值相加,以确定多少小时:x日期发生的路线时间的分钟数。这是我必须计算每个记录的总路由时间的代码:
Me.tbTotalRouteTime.Value = Format(DateAdd("n", -50, [ReturnTime]) - [DispatchTime], "Short Time")
我试图在这样的字段中求和:
=Sum([TotalRTTime])
现在我需要调整fomrat,所以我尝试了hhh:nn,但它没有给我正确的结果。我需要什么格式来显示小时和分钟的确切数量?
答案 0 :(得分:0)
可能是:
Me!tbTotalRouteTime.Value = Format(Sum(DateAdd("n", -50, [ReturnTime]) - [DispatchTime]), "h:nn")
如果您要总计24小时或更长时间,则需要自定义功能,例如:
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