首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通路时间之和?

通路时间之和?
EN

Stack Overflow用户
提问于 2018-11-20 14:58:05
回答 1查看 121关注 0票数 1

我在Access中有一个字段,它使用两个时间值之间的日期差来确定总路由时间。现在,我需要将该字段中的所有值加起来,以确定在x日期上发生了多少小时:路由时间的分钟。这是计算每个记录的总路由时间的代码:

代码语言:javascript
复制
Me.tbTotalRouteTime.Value = Format(DateAdd("n", -50, [ReturnTime]) - [DispatchTime], "Short Time")

我试着把它总结在这样的领域:

代码语言:javascript
复制
=Sum([TotalRTTime])

现在我需要调整fomrat,所以我尝试了hhh:nn,但是它没有给出正确的结果。我需要什么格式来显示确切的小时和分钟的数量?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-20 15:18:35

这可能是:

代码语言:javascript
复制
Me!tbTotalRouteTime.Value = Format(Sum(DateAdd("n", -50, [ReturnTime]) - [DispatchTime]), "h:nn")

如果要加到24小时或更长时间,就需要一个自定义函数,例如:

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53395743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档