我正在使用以下代码以 Day:Hour:Minute 格式显示日期差异。
Function TimeSpan(dt1, dt2)
Dim seconds,minutes,hours,days
If (isDate(dt1) And IsDate(dt2)) = false Then
TimeSpan = "00:00:00"
Exit Function
End If
seconds = Abs(DateDiff("S", dt1, dt2))
minutes = seconds \ 60
hours = minutes \ 60
days = hours \ 24
minutes = minutes mod 60
seconds = seconds mod 60
days = days mod 24
if len(hours) = 1 then hours = "0" & hours
TimeSpan = days& ":" & _
RIGHT("00" & hours , 2) & ":" & _
RIGHT("00" & minutes, 2)
End Function
但在某些情况下,它不会产生预期值。
D1=#9/24/2012 8:09:15 AM# and D2=#9/25/2012 8:09:15 AM# gives correct data like 1:24:00 whereas below are producing error when working with VBScript and Excel.
D1=#9/5/2012 8:45:43 AM# and D2=#9/25/2012 8:45:43 AM# result=0.888888888888889
D1=#9/6/2012 8:29:34 AM# and D2=#9/17/2012 8:59:36 AM# result=0.503125
你能解释一下为什么会这样吗?
谢谢