VBScript DateDiff Function
Complete VBScript Reference Manual
The DateDiff function returns the number of time intervals between two dates.
Syntax
DateDiff(interval,date1,date2[,firstdayofweek[,firstweekofyear]])
| Parameters | Description |
|---|---|
| interval | Required. The unit of time interval used to calculate the difference between date1 and date2.
The following values can be used: |
The following values can be used:
- 0 = vbUseSystemDayOfWeek - use the Regional Language Support (NLS) API setting
- 1 = vbSunday - Sunday (default)
- 2 = vbMonday - Monday
- 3 = vbTuesday - Tuesday
- 4 = vbWednesday - Wednesday
- 5 = vbThursday - Thursday
- 6 = vbFriday - Friday
- 7 = vbSaturday - Saturday
The following values can be used:
- 0 = vbUseSystem - use the Regional Language Support (NLS) API setting
- 1 = vbFirstJan1 - start with the week in which January 1 falls (default)
- 2 = vbFirstFourDays - start with the first week that has at least four days in the new year
- 3 = vbFirstFullWeek - start with the first full week in the new year
Example
Example 1
The difference between January 31, 2009 and January 31, 2010:
The example above produces the following output:
1
4
12
365
365
52
53
8783
527039
31622340
Try it »
Example 2
How many weeks between December 31, 2009 and December 31, 2012 (starting on Monday):
The example above produces the following output:
156
Try it »
Complete VBScript Reference Manual