The DateDiff function returns the number of time intervals between two dates.
|
Syntax | ||||
|
DateDiff(Interval, Date1, Date2 [, FirstDayOfWeek [, FirstWeekOfYear] ]) | ||||
|
Return value | ||||
|
Type |
Description | |||
|
Long |
Number of time intervals. | |||
|
Parameter | ||||
|
Use |
Name |
Type |
Passing |
Description |
|
Required |
Interval |
String |
ByVal |
See below. |
|
Required |
Date1 |
Double |
ByVal |
Determines the first date. |
|
Required |
Date2 |
Double |
ByVal |
Determines the second date. |
|
Optional |
FirstDayOfWeek |
Variant |
ByVal |
Determines the first day of the week. |
|
Optional |
FirstWeekOfYear |
Variant |
ByVal |
Determines the first week of the year. |
Interval determines the time interval to be used to calculate the difference between Date1 and Date2. The following values can be specified for Interval:
|
Interval |
Description |
|
yyyy |
Year |
|
q |
Quarter |
|
m |
Month |
|
y |
Day of the year |
|
d |
Day |
|
w |
Weekday |
|
ww |
Week |
|
h |
Hour |
|
n |
Minute |
|
s |
Second |
You can use the optional FirstDayOfWeek parameter to define the first day of the week.
|
FirstDayOfWeek |
Description |
|
1 |
Sunday (= Default value) |
|
2 |
Monday |
|
3 |
Tuesday |
|
4 |
Wednesday |
|
5 |
Thursday |
|
6 |
Friday |
|
7 |
Saturday |
The optional FirstWeekOfYear parameter determines the first week of the year, which is defined by default as the week in which January 1 is located. The following definitions are possible here:
|
FirstWeekOfYear |
Description |
|
1 |
Week of January, 1st |
|
2 |
Week in which at least four days of the new year are |
|
3 |
first full week of the new year |
Example:
Dim Diff As Long
Diff := DateDiff("d", DateSerial(2000, 5, 6), DateSerial(2000, 5, 7)) # retrieves 1
Diff := DateDiff("d", DateSerial(2000, 5, 7), DateSerial(2000, 5, 6)) # retrieves -1
Diff := DateDiff("ww", DateSerial(2000, 5, 7), DateSerial(2000, 6, 7)) # retrieves 5