DateDiff
Count = DateDiff ( Date1 AS Date , Date2 AS Date , Period AS Integer ) AS Integer
Returns the number of periods between two dates.
  - 
Date1 is the start date.
 
  - 
Date2 is the end date.
 
  - 
Period is the kind of period: year, month, day, week...
 
  
The number of periods is returned.
Period can be one of the following constants:
| 
Constant
 | 
Effect
 | 
gb.Millisecond
 | 
Returns the number of milliseconds.
 | 
gb.Second
 | 
Returns the number of seconds.
 | 
gb.Minute
 | 
Returns the number of minutes.
 | 
gb.Hour
 | 
Returns the number of hours.
 | 
gb.Day
 | 
Returns the number of days.
 | 
gb.Week
 | 
Returns the number of weeks.
 | 
gb.WeekDay
 | 
Returns the number of week days (ignores Saturday and Sunday).
 | 
gb.Month
 | 
Returns the number of months.
 | 
gb.Quarter
 | 
Returns the number of quarters.
 | 
gb.Year
 | 
Returns the number of years.
 | 
Only entire periods are returned. The result is rounded down.
Examples
PRINT DateDiff("01/02/2005 12:55:00", "01/01/2005", gb.Day)
This example shows how DateDiff works internally.
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
 
 
See also