Ms access VBA-Access 2010-Can';t如果超过2天,则以DD:HH:MM格式显示总分钟数
我需要在VBA中将总分钟数转换为Access 2010的DD:HH:MM格式。HH:MM很简单,我能够像这样解析24小时内的总时间:Ms access VBA-Access 2010-Can';t如果超过2天,则以DD:HH:MM格式显示总分钟数,ms-access,time,vba,ms-access-2010,Ms Access,Time,Vba,Ms Access 2010,我需要在VBA中将总分钟数转换为Access 2010的DD:HH:MM格式。HH:MM很简单,我能够像这样解析24小时内的总时间: If total / 1440 > 1 Then tbTimeTotal.Value = "1:" & Format(total / 60 / 24, "hh:nn") Else tbTimeTotal.Value = Format(total / 60 / 24, "hh:nn") End If 但我尝试了48小时以上的解决方案却
If total / 1440 > 1 Then
tbTimeTotal.Value = "1:" & Format(total / 60 / 24, "hh:nn")
Else
tbTimeTotal.Value = Format(total / 60 / 24, "hh:nn")
End If
但我尝试了48小时以上的解决方案却没有奏效:
第一次尝试:
If total / 2880 > 2 Then
tbTimeTotal.Value = "2:" & Format(total / 60 / 24, "hh:nn")
ElseIf total / 1440 > 1 And total / 2880 < 2 Then
tbTimeTotal.Value = "1:" & Format(total / 60 / 24, "hh:nn")
Else
tbTimeTotal.Value = Format(total / 60 / 24, "hh:nn")
End If
如果总计/2880>2,则
tbTimeTotal.Value=“2:”&格式(total/60/24,“hh:nn”)
如果总计/1440>1,则总计/2880<2
tbTimeTotal.Value=“1:”&格式(总计/60/24,“hh:nn”)
其他的
tbTimeTotal.Value=格式(total/60/24,“hh:nn”)
如果结束
第二次尝试:
If total > 2880 Then
tbTimeTotal.Value = "2:" & Format(total / 60 / 24, "hh:nn")
ElseIf total > 1440 And total < 2880 Then
tbTimeTotal.Value = "1:" & Format(total / 60 / 24, "hh:nn")
Else
tbTimeTotal.Value = Format(total / 60 / 24, "hh:nn")
End If
如果总数>2880,则
tbTimeTotal.Value=“2:”&格式(total/60/24,“hh:nn”)
如果总计>1440且总计<2880,则
tbTimeTotal.Value=“1:”&格式(总计/60/24,“hh:nn”)
其他的
tbTimeTotal.Value=格式(total/60/24,“hh:nn”)
如果结束
建议?我可以尝试一种更优雅的方法吗?使用
DateAdd
将总分钟数添加到第0天,这将为您提供一个日期/时间值。然后,可以使用日期和时间以及具有该值的其他标准VBA函数来创建自定义时间格式
以下是一些基于以下函数的示例:
?自定义时间格式(720)
12:00
? CustomTimeFormat(790)
13:10
? CustomTimeFormat(1510)
1:01:10
? CustomTimeFormat(2955)
2:01:15
注意,您不需要从问题中编写所有这些数学运算,因为VBA函数自动处理这些细节
公共函数CustomTimeFormat(ByVal长度等于字符串)
暗淡的长发
作为字符串的Dim strTime
作为字符串的暗输出
Dim DTE与日期等效
DteeEquivalent=DateAdd(“n”,pMinutes,0)
lngDays=CLng(日期值(DTEEEquivalent))
strTime=格式(数据等价于“hh:nn”)
strOutput=vbNullString
如果lngDays>0,则
strOutput=lngDays&“:”
如果结束
strOutput=strOutput&strTime
CustomTimeFormat=strOutput
端函数