VBScript DateDiff
Function
The DateDiff function returns the number of time intervals between two dates.
Syntax
Parameter | Description |
---|---|
interval | Required. The unit of time to use when calculating the difference between date1 and date2. Possible values are: yyyy - Year<br> q - Quarter<br> m - Month<br> y - Day of the year<br> d - Day<br> w - Day of the week<br> ww - Week of the year<br> h - Hour<br> n - Minute<br> s - Second |
date1, date2 | Required. Date expressions. The two dates to be used in the calculation. |
firstdayofweek | Optional. Specifies the day of the week. Possible values are: 0 = vbUseSystemDayOfWeek - Use NLS API setting<br> 1 = vbSunday - Sunday (default)<br> 2 = vbMonday - Monday<br> 3 = vbTuesday - Tuesday<br> 4 = vbWednesday - Wednesday<br> 5 = vbThursday - Thursday<br> 6 = vbFriday - Friday<br> 7 = vbSaturday - Saturday |
firstweekofyear | Optional. Specifies the first week of the year. Possible values are: 0 = vbUseSystem - Use NLS API setting<br> 1 = vbFirstJan1 - Starts with the week in which January 1 occurs (default)<br> 2 = vbFirstFourDays - Starts with the first week that has at least four days in the new year<br> 3 = vbFirstFullWeek - Starts with the first full week in the new year |
Example
Example 1
Difference between January 31, 2009, and January 31, 2010:
The output for this example is:
Example 2
Number of weeks between December 31, 2009, and December 31, 2012 (starting on Monday):
The output for this example is: