如何计算二个时间差?

tophoney 2004-03-09 12:25:59
精确到秒,但结果用天表示,如

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

结果是多少天?如何运算?
...全文
64 点赞 收藏 3
写回复
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基础类
创建于2007-09-28

7522

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2004-03-09 12:25
社区公告
暂无公告