示例代码:
Dim time1 As Date
Dim time2 As Date
Dim td as date
time1 = "2013-6-27 6:52:22"
time2 = "2013-6-28 13:52:14"
td=datediff("ss",time1,time2)
这个只可以求出相差多少秒,还需要你自己进位求出是几秒几分几小时,你可以自己百度"datediff"的用法!其实vb提供了一个计算两个日期相差的函数datediff,
在实际应用之中我们可以进行日期相减运算,但是vb推荐的还是
使用vb自己提供的内部函数为好!
一个例子:
Private Sub Command1_Click()
Dim days As Integer
Dim data1 As Date
Dim data2 As Date
data1 = #2/21/2006# 'O2 / 21 / 2006
data2 = #3/21/2006#
days = DateDiff("d", data1, data2)
Text1Text = Str(days)
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)