DateDiff function
Returns the value of Variant (Long) indicating the number of time intervals between two specified day periods.
Syntax DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
The following named parameters are included in the DateDiff function syntax:
Partial description interval is necessary. String expression, representing the time interval used to calculate the time difference between date1 and date2
Date1□date2 Required;Variant (Date). The two dates to be used in the calculation.
Firstdayofweek is optional. Specifies the constant for the first day of a week. If not specified, Sunday is the first day.
firstweekofyear optional. Specifies the constant for the first week of the year. If not specified, the week containing January 1 is the first week.
Setting the setting value of the interval parameter is as follows: (Setting description)
yyyy year
Q Season
m month
y Number of days in one year
d Day
w Number of days of a week
ww
h
n minutes
s seconds
The set value of the firstdayofweek parameter is as follows: (Description of constant value)
vbUseSystem 0 Use the NLS API settings.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
Constant value description
vbUseSystem 0 Set up with the NLS API.
vbFirstJan1 1 starts from the week containing January 1 (default).
vbFirstFourDays 2 starts with the first of its most half week in the week of the new year.
vbFirstFullWeek 3 starts with the first week without inter-year.
illustrate:
The DateDiff function can be used to determine the number of time intervals specified between two dates. For example, you can use DateDiff to calculate how many days apart between two dates, or how many weeks there will be between today and the end of the year. To calculate the number of days where date1 and date2, you can use the number of days (y) or day (d) of one year. When interval is the number of days of a week (w), DateDiff returns the number of weeks during the two-day period. If date1 is Monday, DateDiff calculates the number of Mondays until date2. This number contains date2 but not date1. However, if interval is week (ww), the DateDiff function returns the calendar weeks for a two-day period. It is obtained by calculating the number of Sundays between date1 and date2. If date2 happens to be Sunday, date2 will also be added to the DateDiff count result; but no matter whether date1 is Sunday or not, it will not be counted. If date1 comes later than date2, the return value of the DateDiff function is negative. The firstdayofweek parameter affects the result of calculations using the time interval symbol W or WW. If date1 or date2 is a date text, the specified year becomes a fixed part of that date. However, if date1 or date2 is enclosed in double quotes (" ") and the year is skipped, the current year is inserted into the code each time the expression date1 or date2 is calculated. This allows you to write program code suitable for different years. When calculating the year difference between December 31 and January 1 of the following year, DateDiff returns 1 to indicate a year difference, although it is actually only one day.