Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Function Declaration
-
Function DateDiff(Interval As String, Date1 As Variant, Date2 As Variant, Optional FirstDayOfWeek As VbDayOfWeek = vbSunday, Optional FirstWeekOfYear As VbFirstWeekOfYear = vbFirstJan1 )
Parameter |
Description |
---|---|
Interval |
String data value (section 2.1) that specifies the interval of time to use to calculate the difference between Date1 and Date2. |
Date1, Date2 |
The two dates to use in the calculation. |
FirstDayOfWeek |
A constant that specifies the first day of the week. If not specified, Sunday is assumed. See section 6.1.1.7. |
FirstWeekOfYear |
A constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs. |
-
Runtime Semantics.
Returns a Long data value specifying the number of time intervals between two specified dates.
The Interval argument is interpreted according to this table:
Interval Data Value
Meaning
"yyyy"
Year
"q"
Quarter
"m"
Month
"y"
Day of year
"d"
Day
"w"
Weekday
"ww"
Week
"h"
Hour
"n"
Minute
"s"
Second
Any other data value
Raise Error 5, "Invalid procedure call or argument"
The interpretation of the Interval data value is not case sensitive.
If Date1 falls on a Monday, DateDiff counts the number of Mondays until Date2. It counts Date2 but not Date1. If interval is Week ("ww"), however, the DateDiff function returns the number of calendar weeks between the two dates. It counts the number of Sundays between Date1 and Date2. DateDiff counts Date2 if it falls on a Sunday; but it doesn't count Date1, even if it does fall on a Sunday.
If Date1 refers to a later point in time than Date2, the DateDiff function returns a negative number.
The FirstDayOfWeek argument affects calculations that use the "w" and "ww" interval symbols.
When comparing December 31 to January 1 of the immediately succeeding year, DateDiff for Year ("yyyy") returns 1 even though only a day has elapsed.
For Date1 and Date2, if the Calendar property setting is Gregorian, the supplied date MUST be Gregorian. If the calendar is Hijri, the supplied date MUST be Hijri.