# 如何计算二个时间差？

tophoney 2004-03-09 12:25:59

(2004-2-8 20:32:02) - (2004-2-9 1:03:20)

...全文
64 点赞 收藏 3

3 条回复

helanshan 2004-07-30
Private Sub Command1_Click()

Dim d1 As Date
Dim d2 As Date

d1 = "2004-2-8 20:32:02"
d2 = "2004-2-9 1:03:20 "

Print (d2 - d1) * 24 '乘24返回小时，乘24再乘60返回分钟，乘 24再乘3600 返回秒 ，不乘返回天数

End Sub

northwolves 2004-07-30
Private Sub Command1_Click()
Dim x As Single
x = CDate("2004-2-8 20:32:02") - CDate("2004-2-9 1:03:20")
MsgBox x & " 天" & vbCrLf & x * 3600 * 24 & " 秒"
End Sub

function GetDoTime(Time1, Time2)

Dim stime
If Time1 > Time2 Then
stime = Time1
Time1 = Time2
Time2 = stime
End If
secondvalue = DateDiff("s", Time1, Time2)
dayvalue = DateDiff("d", Time1, Time2)
hourvalue = Fix((secondvalue - dayvalue * 24 * 3600) / 3600)
If hourvalue < 0 Then dayvalue = dayvalue - 1: hourvalue = 24 + hourvalue
minitevalue = Fix((secondvalue - dayvalue * 24 * 3600 - hourvalue * 3600) / 60)
If minitevalue < 0 Then hourvalue = hourvalue - 1: minitevalue = 60 + minitevalue
secvalue = secondvalue - dayvalue * 24 * 3600 - hourvalue * 3600 - minitevalue * 60
If secvalue < 0 Then minitevalue = minitevalue - 1: secvalue = 60 + secvalue
GetDoTime=dayvalue & "天" & hourvalue & "小时" & minitevalue & "分" & secvalue & "秒"

End function

VB基础类

7522

VB 基础类

2004-03-09 12:25