我在Access中有一个字段,它使用两个时间值之间的日期差来确定总路由时间。现在,我需要将该字段中的所有值加起来,以确定在x日期上发生了多少小时:路由时间的分钟。这是计算每个记录的总路由时间的代码:
Me.tbTotalRouteTime.Value = Format(DateAdd("n", -50, [ReturnTime]) - [DispatchTime], "Short Time")我试着把它总结在这样的领域:
=Sum([TotalRTTime])现在我需要调整fomrat,所以我尝试了hhh:nn,但是它没有给出正确的结果。我需要什么格式来显示确切的小时和分钟的数量?
发布于 2018-11-20 15:18:35
这可能是:
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 Functionhttps://stackoverflow.com/questions/53395743
复制相似问题