我的报告有多个时差。例如,有以下字段
3天4小时15分钟
6小时12分钟
1小时15分钟
并且有许多分组的部分......我想要每个部分的时间总和。
答案 0 :(得分:0)
可以通过将时间转换为秒并将其添加来解决上述问题。
有一个函数可以将秒的总数转换为天/小时/分钟和秒。
Function DHMS(Date1 As Date, Date2 As Date) As String
Dim NumberOfSeconds As Long
Dim NumberOfMinutes As Long
Dim NumberOfHours As Long
Dim NumberOfDays As Long
'Number of seconds between the two dates
NumberOfSeconds = Abs(DateDiff("s", Date1, Date2))
'Calculate Days and remaining Seconds
NumberOfDays = NumberOfSeconds \ 86400
NumberOfSeconds = NumberOfSeconds Mod 86400
'Calculate Hours and remaining Seconds
NumberOfHours = NumberOfSeconds \ 3600
NumberOfSeconds = NumberOfSeconds Mod 3600
'Calculate Minutes and remaining Seconds
NumberOfMinutes = NumberOfSeconds \ 60
NumberOfSeconds = NumberOfSeconds Mod 60
'Return the time remaining
DHMS = NumberOfDays & " Day" & _
IIf(NumberOfDays = 1, " ", "s ") & _
NumberOfHours & " Hour" & _
IIf(NumberOfHours = 1, " ", "s ") & _
NumberOfMinutes & " Minute" & _
IIf(NumberOfMinutes = 1, " ", "s ") & _
NumberOfSeconds & " Second" & _
IIf(NumberOfsecondss = 1, "", "s")
End Function