DateDiff
Count = DateDiff ( Date1 AS Date , Date2 AS Date , Period AS Integer ) AS Integer
返回两个日期之间的时间间隔数。
-
Date1 是较早的日期。
-
Date2 是较晚的日期。
-
Period 是一种时间间隔:年,月,日,星期...。
返回时间间隔数量。
Period 可以是一个下列的常数:
仅返回整数个时间间隔,结果被向下圆整。
示例
PRINT DateDiff("01/02/2005 12:55:00", "01/01/2005", gb.Day)
该示例展示DateDiff内部如何工作
DIM date1 AS Date
DIM date2 AS Date
DIM fDiff AS Float
DIM iDiff AS Integer
date1 = Date(1964, 02, 28, 0, 29, 0
date2 = Date(1964, 03, 01, 0, 30, 0) ' one minute more than two days
fDiff = CFloat(date2) - CFloat(date1)
iDiff = Int(fDiff * 24)
PRINT "first : "; fdiff; " int:"; idiff; " DateDiff:"; DateDiff(date1, date2, gb.Hour)
date1 = Date(1964, 02, 28, 0, 30, 0
date2 = Date(1964, 03, 01, 0, 29, 0) ' one minute less than two days
fDiff = CFloat(date2) - CFloat(date1)
iDiff = Int(fDiff * 24)
PRINT "second : "; fdiff; " int:"; idiff; " DateDiff:"; DateDiff(date1, date2, gb.Hour)
first : 2.000694444403 int:48 DateDiff:48
second : 1.999305555597 int:47 DateDiff:47
参见